📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有29部Youtube影片,追蹤數超過29萬的網紅jaysbabyfood,也在其Youtube影片中提到,#jaysbabyfood #storytime #lgbtinkorea ----------------------------------------- - References - - Ahn, P. (2009). Harisu: South Korean cosmetic media ...
「story mapping」的推薦目錄:
- 關於story mapping 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於story mapping 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於story mapping 在 瑜錄 The O Dora Facebook 的最佳解答
- 關於story mapping 在 jaysbabyfood Youtube 的最佳解答
- 關於story mapping 在 ねこかみこ Youtube 的精選貼文
- 關於story mapping 在 ねこかみこ Youtube 的最佳解答
- 關於story mapping 在 91 敏捷開發之路- 很清楚的user story mapping簡介! 的評價
- 關於story mapping 在 110 User Story Mapping ideas in 2021 - Pinterest 的評價
- 關於story mapping 在 amborle/featmap: The simple and open source user ... - GitHub 的評價
story mapping 在 Taipei Ethereum Meetup Facebook 的精選貼文
📜 [專欄新文章] Solidity Data Collision
✍️ Wias Liaw
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
這是一篇關於 Proxy Contract 和 delegatecall 的注意事項。
Delegatecall
當 A 合約對 B 合約執行 delegatecall 時,B 合約的函式會被執行,但是對 storage 的操作都會作用在 A 合約上。舉例如下:
但是假如多加了一個 other 欄位在 _value 之前,執行合約之後反而是 other 欄位被更改了。
Storage Layout
了解上面的合約之前要先了解 Solidity 怎麼儲存 State Variables。Solidity Storage 以 Slot 為單位,每個 Slot 可以儲存 32 bytes 的資訊,一個 Contract 擁有 2**256 個 Slot。上述可以寫成一個映射關係 mapping(uint256 => bytes32) slots。
Solidity 會從 Slot Index 為零開始分配給 State Variable。
除了 mapping 和 dynamically-sized array,其他的 State Variable 會從 index 為零的 slot 開始被分配。
沒有宣告確切大小的 Array 會以 Slot Index 計算出一個雜湊值並將其作為 Slot Index。透過計算 keccak256(slot) 可以得知 _arr[0] 被存在哪裡,如果要取得 _arr[1] 則將計算出來的雜湊加上 Array 的 index 即可。
Mapping 則是以 Slot Index 和 Key 計算出一個雜湊值並將其作為 Slot Index。透過計算 keccak256(key, slot) 可以得到 mapping(key => value) 被存在哪。
Storage Collision
回到 DelegateExample_v2 的合約,對 B 來說, add 最後儲存加法的 Slot Index 為零,所以使用 A 的 Storage 執行 B 的函式結果自然會儲存在 A 的 other 裡,其 Slot Index 為 0。
這個問題也發生在 Proxy Contract,Layout 如下,當有需要更改 _owner 的操作,就會順帶把 _implementation 也更改了。
|Proxy |Implementation ||--------------------------|-------------------------||address _implementation |address _owner | <= collision|... |mapping _balances || |uint256 _supply || |... |
OpenZeppelin 處理的手法也很簡單,就是將 _implementation 換地方擺。以特定字串的雜湊值作為 Slot Index,儲存 Implementation 的地址。
|Proxy |Implementation ||--------------------------|-------------------------||... |address _owner ||... |mapping _balances ||... |uint256 _supply ||... |... ||address _implementation | | <= specified|... | |
openzeppelin-contracts/ERC1967Upgrade.sol at 83644fdb6a9f75a652d2fe2d96cb26073a14f6f8 · OpenZeppelin/openzeppelin-contracts
hardhat-storage-layout
如何知道合約的 Storage Layout 呢?這邊推薦一個 Hardhat Plugin,按照文件就能得到合約的 Storage Layout。
Ethereum development environment for professionals by Nomic Labs
Reference
Understanding Ethereum Smart Contract Storage
Collisions of Solidity Storage Layouts
Proxy Upgrade Pattern - OpenZeppelin Docs
Solidity Data Collision was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
story mapping 在 瑜錄 The O Dora Facebook 的最佳解答
【中文創意寫作班】
為甚麼我們會用mind-mapping(心智圖)教寫作?
心智圖是我最常用的思考及組織工具。當我還是初中生時,無意中在公共圖書館接觸到類似心智圖的工具,自此開始使用心智圖來做筆記及幫助思考。心智圖讓我當時寫作、做閱讀理解及溫習時事半功倍,每次測驗或考試前所需花的時間不多,但效果不俗—每次都有多科拿100分。
後來,我在工作上也多使用心智圖與同事或實習生一起分析及構思項目。近年我有幸參與不少國際比賽或項目,心智圖也是必用的工具。三年前,我在某個精英雲集、各地政府輪流主辦的國際大賽中,也是以心智圖再結合story-telling技巧助團隊獲全球第二名。
用心智圖來構思文章的效果明顯。附圖是小飛牛冒險故事的心智圖,看著這幅心智圖,每個學生都能輕鬆寫好這個故事。作為Certified MBTI及MMTIC Practitioner,我會指導學生按其性格來善用心智圖,取得更佳效益。Sensing的學生傾向用五感及經驗來學習,不習慣想像,有時會過於重視無謂的細節而忽略重點,文章會顯得片段化而無重點,難以取分。我會教他們用bottom up appoach來提煉重點,刪減細節,並拓展想法。Intuition的學生則滿腦子想法,難以下筆創作,寫作時有時會忽略了闡述觀點及事件。我會他們運用心智圖來將自己的想法排優次,再拓展觀點,闡述事件。當然,其他的性格面向皆有其強項與挑戰,懂得善用心智圖,就能發揮所長,補足其短。
新一期的八堂課,不同性格的學生將會使用心智圖來分析中小學最常見的題目、想像、構思、創造、拓展、舖排及計劃文章。此外,學生亦會學懂如何使用心智圖來做筆記及掌握閱讀理解技巧,讓學生能更輕鬆學習。據我們以往的經驗所得,學生使用心智圖後,其學習效率會提升約30%。
對象:
小一至小四學生
日期及時間:
2021年3月24日至5月12日(逢周三,共八堂)
16:00-17:00
17:00-18:00
18:00-19:00
2021年3月27日至5月15日(逢周六,共八堂)
13:00-14:00
2021年4月5日至5月24日(逢周一,共八堂)
16:00-17:00
17:00-18:00
18:00-19:00
報名:
https://forms.gle/LSFraHE4LUyLokYG9
舊生優先報名,每班首8位報名者將電郵通知繳費資料,其他報名者按報名之先後次序候補
名額有限,以繳交學費作實,先到先得,額滿即止
報讀小四至中二恆常班:https://forms.gle/JsgeJTmj9cgT2s8X8
story mapping 在 jaysbabyfood Youtube 的最佳解答
#jaysbabyfood #storytime #lgbtinkorea
-----------------------------------------
- References -
- Ahn, P. (2009). Harisu: South Korean cosmetic media and the paradox of transgendered neoliberal embodiment. Discourse, 31(3), 248-272.
- Arora, S., Singhai, M., & Patel, R. (2011). Gender & Education determinants of individualism — Collectivism: A study of future managers. Indian Journal of Industrial Relations, 47(2), 321-328.
- Berry, C. (2001). Asian values, family values: Film video, and lesbian and gay identities. In Sullivan, G., & Jackson P. (Ed.), Gay and lesbian Asia: Culture, identity, community. (pp. 211-232). Binghamton, NY: Harrington Park Press.
- Bong, Y. D. (2008). The gay rights movement in democratizing Korea. Korean Studies, 32(1), 86-103.
- Cho, J. P. (2009). The wedding banquet revisited: "Contract marriages" between Korean gays and lesbians. Anthropological Quarterly, 82(2), 401-422.
- Choi, J. S. (2014). Korean culture orientation: Daily-life and religious culture volume. Sonamoo Publishing.
- Jang, H. S. (n.d.). Resource center of young women service review (늘푸른 사업 리뷰). Retrieved from http://www.seoul.go.kr/info/organ/center/1318_new/info/review/1253299_13874.html
- Kim, H. Y., & Cho, J. P. (2011). The Korean gay and lesbian movement 1993-2008: from "identity" and "community" to "human rights". South Korean Social Movements: From Democracy to Civil Society, 206-223.
- Kim, Y., & Hahn, S. (2006). Homosexuality in ancient and modern Korea. Culture, Health & Sexuality, 8(1), 59-65.
- Kwak. L. G. (2012, April 25). Who murdered a 19-year old LGBT teen (누가 열아홉살 동성애자를 죽였나). Oh My News. Retrieved from http://www.ohmynews.com/nws_web/view/at_pg.aspx? CNTN_CD=A0001724998
- Lee, J. E. (2006). Beyond pain and protection: Politics of identity and iban girls in Korea. In Khor, D., & Kamano, S. (Ed.), Lesbians in east Asia: Diversity, identities, and resistance. (pp. 49-67). Binghamton, NY: Harrington Park Press.
- Novak, K. (2015). The problem with being gay in South Korea. Retrieved from http://edition.cnn.com/2015/10/18/asia/south-korea-being-gay/
- Park, H., Blenkinsopp, J., Oktem, M., & Omurgonulsen, U. (2008). Cultural orientation and attitudes toward different forms of whistleblowing: A comparison of South Korea, Turkey, and the U.K. Journal of Business Ethics, 82(4), 929-939.
- Seo, D. J. (2001). Mapping the vicissitudes of homosexual identities in South Korea. Journal of Homosexuality, 40, 65-79.
- Song, J. (2014). Living on your own: Single women, rental housing, and post-revolutionary affect in contemporary South Korea. SUNY Press.
- Do Koreans Support LGBTQ+? (Ft. Seoul Queer Parade) | ASIAN BOSS https://youtu.be/p_vsIEs72p8
- Koreans React To K-pop Singer Coming Out As Bisexual [Street Interview] | ASIAN BOSS https://www.youtube.com/watch?v=BKL9VrqLJZE
- Is South Korea's LGBT+ community being scapegoated for COVID-19 spread? https://www.dw.com/en/is-south-koreas-lgbt-community-being-scapegoated-for-covid-19-spread/a-53423958
----------------------------------------
- SNS -
Facebook: https://www.facebook.com/jaysbabyfood/
Twitter: https://twitter.com/jaysbabyfood
Instagram: https://www.instagram.com/jaysbabyfood/
----------------------------------------
- Production -
✂️Final Cut Pro
Music by Eric Reprid - Back to Business - https://thmatc.co/?l=3ED40649
Music by ninjoi. - Acceptance - https://thmatc.co/?l=B8A316A
Music by Cassette Tapes - Balance - https://thmatc.co/?l=55784255
----------------------------------------
- Business Inquiries Only -
jaysbabyfood@gmail.com
or LINE: @jaysbabyfood (with @)
----------------------------------------
story mapping 在 ねこかみこ Youtube 的精選貼文
最後までご視聴ありがとうございました。
当初はここまで人気企画になると思っていなくて
企画の詰めがとてもあまく…
グダグダした場面も多かったかと思います。
動画の流れをよく思わなかったり、不快な思いをさせてしまった方にはホントに申し訳ないです。
12月にはこのシリーズの続編を投稿していくので
今度は計画的に進めていきます。
ここまでお付き合いしていただき圧倒的感謝。
主要MOD
・MCEconomy2「shift様」
・ Economical Milk Tea!MOD「defeatedcrow様」
・caveworld「kegare様」
・Railcraft 「CovertJaguar様」
今回使用したMOD
・Fake Ores
https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2461487-1-7-10-1-13-2-fake-ores-ores-become-alive-now
前回の返済物語
【Minecraft】マイクラ借金返済物語#16
~1億返すまで帰れません。【ゆっくり実況】
https://youtu.be/_UxY9dkLU-M
OPBGM:Lameguy64
Cave Story (unfinished OPL3 rendition)
https://soundcloud.com/lameguy64/cave-story-unfinished-opl3
EDBGM:Giant Shark + Laser
Cave Story - Theme Song cover concept
https://soundcloud.com/giant-shark-laser/cave-story-theme
BONUSBGM
DJames
Cave Story (DJames Remastered)
https://soundcloud.com/darkdjames/cave-story-darkdjames
Mimiga Village (Adlib/OPL3 Cover)
https://soundcloud.com/lameguy64/mimiga-village-adlib-cover
【過去動画】
【Minecraft】なまけもののマインクラフト 【ゆっくり実況】
https://www.youtube.com/playlist?list=PLH4jv5vJX3-WbpMkNExEptB7PEgWPNl2L
【GMOD】シリーズ
https://www.youtube.com/playlist?list=PLH4jv5vJX3-WKuSfT7K1lZUO3rdDcqF8xx
「フリーBGM・音楽素材MusMus http://musmus.main.jp/」
スポンサー様:DELL ALIENWARE
https://sp-point.net/dell/index_alienware2.html
※こちらから15万円以上(税抜き)お買い上げいただくと、楽天ポイント7,500ポイントをプレゼントいたします。
#マイクラ
#マインクラフト
#ゆっくり実況
twitterフォローもよろしくおねがいします。
https://twitter.com/nekokamiko
story mapping 在 ねこかみこ Youtube 的最佳解答
今回撮れ高が少なくあっさりな内容ですみません・・;
次回最終回です。
主要MOD
・MCEconomy2「shift様」
・ Economical Milk Tea!MOD「defeatedcrow様」
・caveworld「kegare様」
・Railcraft 「CovertJaguar様」
今回使用したMOD
・Fake Ores
https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/minecraft-mods/2461487-1-7-10-1-13-2-fake-ores-ores-become-alive-now
前回の返済物語
【Minecraft】マイクラ借金返済物語#11
~1億返すまで帰れません。【ゆっくり実況】
https://youtu.be/4ZCu7DTaq58
OPBGM:Lameguy64
Cave Story (unfinished OPL3 rendition)
https://soundcloud.com/lameguy64/cave-story-unfinished-opl3
EDBGM:Giant Shark + Laser
Cave Story - Theme Song cover concept
https://soundcloud.com/giant-shark-laser/cave-story-theme
BONUSBGM
DJames
Cave Story (DJames Remastered)
https://soundcloud.com/darkdjames/cave-story-darkdjames
【過去動画】
【Minecraft】なまけもののマインクラフト 【ゆっくり実況】
https://www.youtube.com/playlist?list=PLH4jv5vJX3-WbpMkNExEptB7PEgWPNl2L
【GMOD】シリーズ
https://www.youtube.com/playlist?list=PLH4jv5vJX3-WKuSfT7K1lZUO3rdDcqF8xx
「フリーBGM・音楽素材MusMus http://musmus.main.jp/」
スポンサー様:DELL ALIENWARE
https://sp-point.net/dell/index_alienware2.html
※こちらから15万円以上(税抜き)お買い上げいただくと、楽天ポイント7,500ポイントをプレゼントいたします。
twitterフォローもよろしくおねがいします。
https://twitter.com/nekokamiko
story mapping 在 110 User Story Mapping ideas in 2021 - Pinterest 的推薦與評價
Oct 3, 2021 - Story Mapping is a better way to work with Agile User Stories. User Story Mapping is a dead simple idea. Talk about user's journey through ... ... <看更多>
story mapping 在 amborle/featmap: The simple and open source user ... - GitHub 的推薦與評價
Story mapping was created by Jeff Patton and its primary utility is providing us with an overview of the entire product and how user goals are broken down into ... ... <看更多>
story mapping 在 91 敏捷開發之路- 很清楚的user story mapping簡介! 的推薦與評價
[筆記] User Story Mapping in Agile Tour Taipei 2016. https://juggernaut-liu.blogspot.tw/2016/12/user-story-mapping-in-agile-tour-taipei.html 這場sessio. ... <看更多>