📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有55部Youtube影片,追蹤數超過5萬的網紅Daphne Iking,也在其Youtube影片中提到,???????? ??? ???????? Mistakes and failures are part and parcel of life and great learning curves. Just don’t repeat the same mistake lah. In my c...
「in normal case」的推薦目錄:
- 關於in normal case 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於in normal case 在 本土研究社 Liber Research Community Facebook 的最佳解答
- 關於in normal case 在 Facebook 的精選貼文
- 關於in normal case 在 Daphne Iking Youtube 的最佳貼文
- 關於in normal case 在 Tang_ful Youtube 的精選貼文
- 關於in normal case 在 Poyja Youtube 的最佳貼文
- 關於in normal case 在 Stereo Normal Case - 5 Minutes with Cyrill - YouTube 的評價
- 關於in normal case 在 Converting snake case to normal sentence in Ruby - Stack ... 的評價
in normal case 在 本土研究社 Liber Research Community Facebook 的最佳解答
【渾水一片:還原香港海界爭議發展史】 (上篇) #都市化洋謀 #9月專研
過往在香港討論有關海洋邊界爭議,往往是香港以南的南海主權問題。事實上近年的焚船污染、明日大嶼、12人越洋、走私不斷等當下議題,都與海洋空間規劃、定界及海權問題有關,而香港早年殖民期的海界及海權作為各種海洋亂象之源,卻少有人深入探討。
翻查一系列關於香港水域爭議的英國解密檔案,整理過往殖民地時期有關香港「含糊」水域爭議的發展史,揭示牽涉複雜的海洋邊界政治,除了作為當時中英政治角力的前緣,亦有助我們了解現時香港水域範圍的歷史脈絡及源起。
一條海界 兩個表述
殖民地時期早年,香港的水域範圍一直未有公開確實的版本,亦引伸出有兩種不同的界線表述。
於20世紀初,根據《展拓香港界址專條》的香港地圖顯示,香港水域呈「方型」界線(square boundary )。根據一份關於新界邊界及現況的英國解密檔案(1962 CO 1030/1334 Status and boundaries of Hong Kong New Territories),當時中方海關經常巡邏於以大嶼山以西大澳水域一帶(方型界線以外),似乎更視其為中方水域。然而,早在1901年英方已有向港督提及,按照國際上的海洋慣例,一般領海 (normal territorial waters)寬度應為3海里 (three nautical miles),因而,香港領海界線應呈現為「彎曲型」(sinuous),比起「方形」範圍雖然多了大嶼山以西水域,同時卻損失了東南方一大片水域,作為最早期的香港水域範圍的兩個表述。
後續1911年修訂《釋義條例》(Interpretation Ordinance) 時,由於港督的錯誤公告字眼(wording of an incorrect Proclamation),令到香港水域繼續被闡釋為方型。
而這個錯誤的公告去到1950年被修訂。英方於1950年重新檢視與領海相關的條例,表示若沿用1937年英方對於《釋義條例》的闡釋,地圖所顯示的「方形」界線,只是英方租用中方領土的一條分界線(merely a line of delimitation of the area within which all territory was leased) ,並不是租用香港3海里以外的水域範圍(this did not mean that there was a purported lease of any waters outside normal territorial waters),可見,內部確立「彎曲型」的領海範圍。
參考一份1950年關於香港水域的英國解密檔案 (1950 CO 537 6036 Territorial water) 中的英方外交部內閣大臣Jim Griffiths跟港督的電報來往中顯示,因當時中日關係惡劣,為了保持當時英方中立 (neutral) 的立場。英方亦想盡量避免中日雙方於香港水域範圍發生衝突 (Jørgensen N. H. B., 2019),早於1937年至1939年,英方曾經指示香港水域要跟隨國際慣例,將領海寬度收窄至3海里。無獨有偶,1950年修訂《釋義條例》,已有英方法律意見表示當時擔心如果國、共兩軍在新海界(彎曲型)及舊海界(方型)之間的位置發生衝突,將會造成英方外交上尷尬,要盡快修例避免尷尬事件。可見,英方變動水域邊界時明顯有其政治考量。
即使已修例,1952年當時國際法庭 (International Court of Justice) 有關英挪漁業案(Anglo Norwegian Fisheries case)的判決 (Jørgensen N. H. B., 2019),提及使用哪種基線方式來劃定領海的爭議,促使香港律政司重提「方型」領海是否合法地代表香港水域,但建議被英方否決。其後在1958年,即使英國外交部再次表示「方型」範圍只是表示港英領土的一條分界線 (all land within the line thus shown is Hong Kong territory),但同時亦保留方型界線,聲稱為免影響航空航線。
早年香港水域邊界一直未被確實,即使在法律層面上,英方內部確立「彎曲型」領海範圍的合法性。然而,其後英方一直未有公開與中國共產黨政權講述其水域範圍,或擔心會侵犯中國領海主權。可見,香港水域一直受到變動中的海緣政治影響,經常遊走在當時國際上認可海洋慣例(彎曲型)與中英簽訂的《展拓香港界址專條》(方型)之間。
中方圍堵香港水域的預言?
水域範圍、基線劃定的方法及國際航海權一直是國際外交上一個十分敏感的議題。香港作為英國殖民地,卻緊貼住中國的領海範圍,除了香港水域定界,船隻來往香港的航道亦一直是英方十分頭痛的問題,稍有不慎,就會有被冠上侵犯中國海權的「辱華」罪名。
中方於1958年第一次聯合國海洋法公約(United Nations Convention on the Law of the Sea),已經單方面將其領海範圍擴展至12海哩,英國宗主國當時內部表明會反對中方單方面的領海宣稱,擔心會發生圍堵香港水域的情況。
根據新界邊界及現況的英國解密檔案(1962 CO 1030/1334 Status and boundaries of Hong Kong New Territories)中的電報來往,當時港英內部評估,認為中方擴展領海將對香港造成「海陸空」影響,除了會收窄飛機的航道、需要重新佈線電纜和無線電纜、亦會限制海軍的演練空間,大大影響香港的船隻來往,來往公海的航道走廊更會收窄到1海里(corridor of international waters could be reduced to about one mile),形容「接近完全圍封香港」 (almost completely envelope Hong Kong)。
隨著國際共識的改變,在1972年第三次聯合國海洋法會議前夕,英方亦打算將國土領海範圍的3海里擴展至12海里。翻查另一份1972年關於香港水域爭議的英國解密檔案 (1972 FCO 21 1024 Territorial waters dispute between China and Hong Kong),當時英方內部考慮這次擴展海界,應否包括香港殖民地,並計劃在香港附近水域進行海道測量 (Hydrographic survey),明顯想放風測試中方反應。
然而,根據英國外交部及港英的內部電報來往,英方雖然一度打算在翌年與中方在第三次聯合國海洋法會議上提及香港殖民地水域擴展,但英方內部亦指出中方定會反對香港的水域擴展至12海里,除了因為香港擴展會跟中國水域重疊,中國亦一直視香港為固有領土,不可視香港為獨立的行政個體 (separate entity),應該維持現狀,限制今次香港擴海界。
呼應早期50年代有關中方圍堵香港水域的擔憂,英方擔心如果掀起討論,更有可能令香港航道問題惡化 (a risk that any such discussion would vitiate the present adequate though limited freedom of passage)。按英國外交部理解,中方只不過默許船隻在不進入擔桿列島5海哩範圍的前提下進入香港;如果中國「執正嚟做」嚴格實踐其12海里的主權宣稱,則連博寮海峽都不能通行 (a 12 mile limit strictly adhered to in this area would make normal surface access to Hong Kong through the Lemma Channel impossible)。最後,英方外交部為免觸動到中方神經,加上「信唔過」中方 (their good will… cannot be relied on a year ahead),建議的對策卻是避免「打草驚蛇」(let sleeping dogs lie),絕口不提香港擴海界。
直到1987年,英國正式將水域擴展到12海哩,但香港並沒有納入被擴展的範圍。在香港前途談判過程中,亦未有正式提及香港水域擴展12海里一事(Jørgensen N. H. B., 2019)。可見,面對中方進取的領海主權宣稱,英方在香港水域邊界問題上,尤其顯得無力。
香港「渾水」邊界的潛規則
面對中國擴海界後將會圍堵香港的擔憂,根據一份有關香港水域及其爭議的英國解密檔案(1968 FCO 21 547 Dispute with China about territorial waters),當中牽涉中英雙方就香港海界爭議鮮為人知的權宜之計(modus vivendi)。
事緣1968年一艘美國貨船於萬山群島近珠江口一帶(Lema Channel in the estuary of the Pearl River)被中方海軍的警告已入侵中方水域,檔案中有一份美國國務院情報與研究局官員Thoms L. Hughes事後對中國共產黨於香港鄰近水域的主權宣稱(Communist assertions of sovereignty over waters in the vicinity of Hong Kong)進行一份內部評估報告,提到中方不時會「放生」來往香港的商船。
於50年代初,船隻可以經萬山群島近珠江口一帶接近香港水域,可謂當時的潛規則(local ground rule)。然而,在中方宣稱12海里領海後,於1959年曾發出達20次警告,外國商船透過萬山群島近珠江口一帶接近香港期間入侵中方水域,並禁止一切外國船隻通往萬山群島近珠江口一帶,評估報告中亦提及多次美國商船及軍艦通往香港遇上中國海軍的事件。
然而,中方不但少有採取實際軍事行動,多是「口頭」表示抗議及警告外國船隻侵犯中國水域,更沒有對外公開批評數次入侵事件。就以上例子,美方評估中國當時並不是新的「強硬路線」宣示領海主權(new harder line from Peking),只是由於過多船隻進入萬山群島內沿而作出的回應(is a reaction to an increasing number of passages through the interior Lema Channel)[萬山群島內沿被中國視為內海]。
而當時美方估計中方「放生」的動機,很可能取決於政經考量,其一為不想失去香港作為(kill the goose)來往外國商船主要來往中國的航道,以及香港為中國帶來的外匯,而另一原因則是避免發生中國海軍與美國軍艦於海上起衝突。
此外,除了英方一直未有公佈香港水域邊界,中方一直並未有公開宣稱香港以西南的珠江通道12海里的精準劃界(public silence regarding the exact limits of its claim)。中英雙方基於政治考量,對於香港水域劃界及航道,更被美方稱靈活的實用主義(flexible pragmatism)。
而美方認為英方亦知悉船隻來往香港的「後路」,根據一份英方未被公開的非正式文件( informal note)顯示,除了船隻背後的註冊國家將成為影響進入香港的政治因素,英方更提及最合適的接近香港水域的航道,是經萬山群島以南以及擔桿頭島五海里以外(keep to the south of the Lima Group and five miles or more off Tam kan Head),港英政府早於五十年代,已廣傳這份文件到商船公司及中方,有共識地默許外國船隻經香港東南方水域,作為當時來往香港的「後路」。
可見,比起香港陸上的邊界,早期香港水域由定界、擴界到圍堵,可謂「渾水一片」。而當中牽涉複雜的海緣政治,亦顯示香港水域並非一條確確實實的邊界範圍,反而是中英雙方的妥協空間。而後來香港水域邊界將如何落實為現時版本?當中牽涉多少談判?而所引伸的一系列有關領海執法權以至政府管轄權的問題,將揭示香港水域日後跨境執法以至逃犯移交的爭議。(下集待續)
參考資料
Jørgensen, N. H. B. (2019). The (Unequal) Relationship between Hong Kong’s Waters and China’s Baselines. Asia-Pacific Journal of Ocean Law and Policy, 4(1), 1–27.
1950 CO 537/6036 Territorial water
1962 CO 1030/1334 Status and boundaries of Hong Kong New Territories
1968 FCO 21/547 Dispute with China about territorial waters
1972 FCO 21/1024 Territorial waters dispute between China and Hong Kong
1974 FCO 18/154 Hong Kong territorial waters
💪 研究自主 月捐撐起最新專研系列:
https://liber-research.com/support-us/
🔸FPS ID:5390547
🔸HSBC PayMe 捐款支持:https://bit.ly/32aoOMn
🔸戶口號碼:匯豐銀行 640-198305-001 (LIBER RESEARCH COMMUNITY (HK) COMPANY LIMITED)
👨👩👧👦義工招募:https://bit.ly/2SbbyT3 ▫️
in normal case 在 Facebook 的精選貼文
No child should be put in this position - having to plead on behalf of her father (who appears to be abusive and potentially intoxicated)
Unfortunately this scene is probably frightenly normal - except that this case it was caught on camera.
Children should be protected whatever the costs and as a society we need to ensure that their safety and wellbeing is paramount in our priorities.
Whomever has any info or updates about this child or please do let abang @harithiskander know or contact @thehopebranch.my at 019-7093103
#thehopebranch
#kitajagakita
#rakyatuntukrakyat
in normal case 在 Daphne Iking Youtube 的最佳貼文
???????? ??? ????????
Mistakes and failures are part and parcel of life and great learning curves. Just don’t repeat the same mistake lah.
In my case today? Over my Pon Bebels and Masak, I made Muah Chee andddddd forgot to add water to Varoma my glutinous rice mix ….BOLEH? ??♀️
Tulah pasai… bebel punya pasal lupa ikut resepi si Michelle (founder of OILEES)
Nevermind. I is learn my lesson
Here is the MUAH CHEE RECIPE:
INGREDIENTS:
Peanut Sugar Powder:
74gm Roasted Peanuts without skin (You can toast peanuts using the High Temperature : https://cookidoo.international/recipes/recipe/en/r685071
25gm Raw Cane Sugar
Turbo 2sec, set aside
60gm Glutinous Rice Flour
90gm Water
1Tbsp Extra Virgin Olive Oil
PREPARATION:
1. Add flour & water. Mix 1min/speed 3
2.Add oil. Mix 30sec/speed 3
3.Brush a thin layer of oil on metal plate ( I used a normal plate and raised it using the butterfly whisk below to allow steam to go through)
4. Pour mass onto plate and on Varoma Dish
5. Fill the mixing bowl with 1litre of water
Steam 15mins/ Varoma/ speed 1
Cut ( I used dough cutters to "slice" the glutinous into smaller pieces) and mix with Peanut powder. Serve immediately.
Bebels of the Day?
1. Prince Harry and Duchess of Sussex name their second child after Harry's grandmother and mother.
2. Wishing our DYMM di-Pertuan Agong a Happy Birthday. Daulat Tuanku
3. A bit on the controversial sexual harrassment
4. @Boss Mama Malaysia collaboration with APE Malaysia. With every purchase of the Emerald Green Real Support Bra, a tree will be planted under your name at the Lower Kinabatangan Wildlife Sanctuary, Sabah. They will send a cert with your name and GPS of tree planted. Use BOSSBABE code for RM40 OFF your purchase!
5. Mistakes and Failure (this was impromptu since I forgot to add the water in before steaming #aiyo
Catch me tomorrow for another round of Pon Bebels & Masak
#DVaromas
in normal case 在 Tang_ful Youtube 的精選貼文
#ccsub #抽獎
/
發問前請先詳閱資訊欄喔~感謝!!
/
如果你喜歡我的影片歡迎訂閱~我們下支影片再見囉♡
粉絲專頁:https://www.facebook.com/tangful/
Follow my Instagram @tang_ful for more makeup look!!!
IG: https://www.instagram.com/tang_ful/
mail:tangfulmade@gmail.com
/
時間軸:
0:00 開場
7:20 終於要化妝:封眉
14:25 妝前+底妝
23:52 眼妝:手超穩的薔薇
43:00 犀利的提問XD
50:40 不打玻尿酸的豐唇術
54:34 變身TANGFORD(?
/
追蹤薔薇:
IG https://www.instagram.com/chiangweiii/
YT https://www.youtube.com/channel/UCNnUF55YrSXbnv8kofHKZbA/featured
VOGUE投票 https://www.vogue.com.tw/sIA/nominee.php
/
🎁🎁🎁
這支影片我決定要舉辦抽獎唷!
獎品是我會準備驚喜箱(包含全新產品 or 9成新產品,大多是化妝品保養品)
有興趣的朋友歡迎留言參加~
這次的抽獎方式比較特別唷!
我會準備兩份獎品:
一份給開獎前留言讚數最高的人,另一份是由我選出的留言!
所以其中一份得獎者等於是大家選出來的唷🥳
如果有看到很棒很認同的留言就給他一個讚吧!
也歡迎大家把影片分享給親朋好友們
讓更多人認識變裝皇后這個美麗的文化~!!
*一週後在我的IG動態開獎
*留言最後可以附上IG帳號,開獎比較不會漏接通知
*開獎兩天後沒有領獎直接重抽唷!
*主辦者有權調整抽獎規則
/
產品資訊:
• 3M
紫變色無毒配方口紅膠
$45
• RCMA
No Color Powder
約$390
• CINEMA SECRETS
晶透無瑕粉底五色盤-遮瑕天后
$1680
• est
柔光粉底霜
$4200
• J.Cat Beauty
Staysurance Water-Sealed Zero-Smudge Concealer /SHC107 Custard
$197
• NYX
Epic Ink Liner
約$250
• Colourpop
Blowin' Smoke Shadow Palette
約$390
• Make Up For Ever
12 Flash Color Case - Flash
約$2800
• 阿比家
閃亮片眼影彩妝盤12色
約$500
• Profusion Cosmetics
Eye Sparkler Liquid Shadow Twinkle
約$120
• Rare Beauty
Perfect Strokes Matte Liquid Liner
約$530
• Kimchi Chic X Naomi Smalls
sunkissed In June Palette
約$530
• Make Up For Ever
Aqua XL Ink Liner Matte White
約$670
• OFRA
激光打亮盤 / 比佛利山莊Beverly Hills
$1390
• Solone
持久流暢眼線液筆 02深夜棕
$320
• 3INA
精準勾勒唇線筆
$320
• JEFFREE STAR COSMETICS
Velour Liquid Lipstick
約$500
• Dior
癮誘蜜潤光唇彩
$1300
/
Music:
https://player.epidemicsound.com
/
Camera: Canon 80D
My skin type: normal to oil
我的膚質:混合偏油
/
/
/
/
非合作影片
in normal case 在 Poyja Youtube 的最佳貼文
เปิดกระเป๋าผ้า marimekko
มีอะไรอยู่ในกระเป๋าบ้าง , จัดกระเป๋าน่ารักๆ
What's in my bag version new normal
-ลิ้งค์ร้านกระเป๋าไอแพดขนมปัง brunch brother
https://shopee.prf.hn/l/7x3NANG
ig : poy_poyja
ig : japan_diary
in normal case 在 Stereo Normal Case - 5 Minutes with Cyrill - YouTube 的推薦與評價
... <看更多>