📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有120部Youtube影片,追蹤數超過38萬的網紅CH Music Channel,也在其Youtube影片中提到,《マブラヴ オルタネイティヴ》 未来への咆哮 / Asu e no Houkou / 向著未來的咆哮 / The Howl Towards Tomorrow 作詞 Lyricist:影山ヒロノブ 作曲 Composer:影山ヒロノブ 編曲 Arranger:須藤賢一 歌 Singer:JAM Pro...
「be bound for」的推薦目錄:
- 關於be bound for 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於be bound for 在 Nicole Chen - thenictionary Facebook 的最讚貼文
- 關於be bound for 在 Nicole Chen - thenictionary Facebook 的精選貼文
- 關於be bound for 在 CH Music Channel Youtube 的最佳貼文
- 關於be bound for 在 ロイドごはん Youtube 的精選貼文
- 關於be bound for 在 Nicole Chang Youtube 的最讚貼文
be bound for 在 Nicole Chen - thenictionary Facebook 的最讚貼文
THE VULVA FLOWER 🌸
The censorship of our bodies, the ‘offensiveness’ of the female anatomy hurt us all. I’m not talking about our identities, and feminism, or even politics.
I’m talking about women who fear going for Pap smears and check ups, who’re scared to tell their parents they have infections and don’t know what to do, who don’t know about HPV vaccines, and birth control, and put themselves in danger, because society shames our bodies, shames what makes us women, shame what makes us sacred and amazing, and different from men.
I hesitated a little speaking up about this because I had been closely working with @kotexmy on some campaigns, and understood the terms we’re bound by when we work, but when I talked to the representatives down at Kotex, they reassured me that this fight, our fight, is so much bigger than just brands and work. 😭💖
I’m so so happy to be in a place where I can collaborate with people who give me the freedom to stand up for what I believe in, and lend power and voice through me, and recognise in the big picture, we’re all fighting for the same thing. ✨
Our bodies are not shameful, neither are they offensive, nor sexual. Our bodies are strong, wondrous, incredible things that possess the gift of giving life, and it should be celebrated by all, especially other women ✨
I am truly comforted by the idea that in their act to censor our bodies, they accidentally blew the issue up, and ironically it blew back in their faces. 😉 when they come for us, they come for us all, so don’t be surprised when we bite back.
Inspired by @christopher_grave 💖 #vulva #vulvaflower #vulvamakeup #vulvaflowermakeup #vulvaart
be bound for 在 Nicole Chen - thenictionary Facebook 的精選貼文
THE VULVA FLOWER 🌸
The censorship of our bodies, the ‘offensiveness’ of our female anatomy, hurt us all. I’m not talking about our identities, and feminism, and politics.
I’m talking about women who fear going for Pap smears and check ups, who’re scared to tell their parents they have infections and don’t know what to do, who don’t know about HPV vaccines, and birth control, and put themselves in danger, because society shames our bodies, shames what makes us women, shames what makes us sacred and amazing, and different from men.
I hesitated a little speaking up about this because I have been closely working with @kotexmy on some campaigns, and understood the terms we’re bound by when we work, but when I talked to the representatives down at Kotex, they reassured me that this fight, our fight, is so much bigger than just brands. 😭💖
I’m so so happy to be in a place where I can collaborate with people like this. who give me the freedom to stand up for what I believe in, and lend power and voice through me, that in the bigger picture, what we want are all the same.
Our bodies are not shameful, or offensive, or sexual. They are beautiful, and wondrous, and incredible and should be celebrated! ✨
I am so comforted in knowing, in their act of censoring us, they actually blew up the whole thing by accident, and it blew right back in their faces. 😉
be bound for 在 CH Music Channel Youtube 的最佳貼文
《マブラヴ オルタネイティヴ》
未来への咆哮 / Asu e no Houkou / 向著未來的咆哮 / The Howl Towards Tomorrow
作詞 Lyricist:影山ヒロノブ
作曲 Composer:影山ヒロノブ
編曲 Arranger:須藤賢一
歌 Singer:JAM Project featuring 影山ヒロノブ、遠藤正明、きただにひろし、福山芳樹
翻譯:CH(CH Music Channel)
意譯:CH(CH Music Channel)
背景 Background - Official Soundtrack album cover:
https://i.imgur.com/GAMikam.jpg
上傳你的字幕吧! Submit your subtitles here!
https://forms.gle/MSsAM2WHpT31UuUh8
版權聲明:
本頻道不握有任何音樂所有權,亦無任何營利,一切僅為推廣用途。音樂所有權歸原始創作者所有。請支持正版。
Copyright Info:
Be aware this channel is for promotion purposes only without any illegal profit. All music's ownership belongs to the original creators.
Please support the original creator.
すべての権利は正当な所有者/作成者に帰属します。あなたがこの音楽(または画像)の作成者で、この動画に使用されたくない場合はメッセージまたはこのYoutubeチャンネルの概要のメールアドレスにご連絡ください。私はすぐに削除します。
如果你喜歡我的影片,不妨按下喜歡和訂閱,你的支持就是我創作的最大原動力!
If you like my videos, please click like and subscribe! Thx :)
粉絲團隨時獲得最新訊息!
Check my Facebook page for more information!
https://www.facebook.com/chschannel/
中文翻譯 Chinese Translation :
https://home.gamer.com.tw/creationDetail.php?sn=5263823
日文歌詞 Japanese Lyrics :
立ち上がれ 気高く舞え 天命(さだめ)を受けた戦士よ
千の覚悟 身にまとい 君よ 雄々しく 羽ばたけ
闇の時代を告げる 鐘が遠く鳴り響く
戦う友よ 今 君は 死も恐れず
瓦礫の街を染めて 沈む夕日は紅
愛する地球(ほし)の未来を守るため
おお 神の刃は 人類(ひと)の愛
祈りを 込めて つらぬけ
立ち上がれ 気高く舞え 天命(さだめ)を受けた戦士よ
明日の平和への 礎となれ
熱くなれ 大きく咲け 天に捧げし命よ
弱き者の盾となれ そして 世界を 導け
きらめく星の海に 浮かぶ おまえの面影
二度と逢えない愛ゆえに なお いとしい
背中合わせの世界 重ね合えない現実
涙とともに捨て去れ なにもかも
さぁ 振り返らずに 風になれ
痛みを越えて 駆け出せ!!
立ち上がれ 気高く舞え 天命(さだめ)を受けた戦士よ
たとえ傷ついて 力尽きても
赤く燃え 見事に散って 星になった命よ
時を越え その名前を 胸に刻もう Just Forever
立ち上がれ 気高く舞え 天命(さだめ)を受けた戦士よ
たとえ傷ついて 力尽きても
熱くなれ 大きく咲け 天に捧げし命よ
明日の平和への 礎となれ
赤く燃え 見事に散って 星になった命よ
時を越え その名前を 胸に刻もう Just Forever
中文歌詞 Chinese Lyrics :
奮身站起、氣宇昂揚,領受天命的戰士啊
伴隨身懷的千百覺悟,你啊,終將英勇地展翅高飛
遙遠彼方的鐘聲正響遍四方,昭告黑暗時代的降臨
並肩抵抗的戰友啊,現今,你已不再畏懼死亡
西沉的夕日為瘡痍滿目的瓦礫街道,浸染了熾熱的緋紅
只為了守護,屬於這深愛地球的未來
哦,神的刀刃,乃賜予人類的愛
貫徹注入其中的千萬祈願,便無堅不摧
奮身站起、氣宇昂揚,領受天命的戰士啊
化作邁向明日和平的堅固基石吧
熾熱地燃燒、壯烈地綻放這獻予上天的生命
成為保護弱者的堅盾,並引領這個世界吧!
望向熠熠生輝的星海,憶起了你的容貌
正因這是份再也無法重逢的愛,才令我如此眷戀
在兩相互斥的世界,充斥著無法重疊的現實
但將所有一切連同淚水都盡數捨棄吧
來吧!不再回首,而是化作一陣疾風
超越一切傷痛,向前奔馳而去!!!
奮身站起、氣宇昂揚,領受天命的戰士啊
哪怕早已遍體鱗傷;哪怕早已竭盡氣力
將這猶如明星般的生命,熱血地燃燒、璀璨地殞落吧
這個名字定將穿越時空,銘刻於人們心中,直至永恆
奮身站起、氣宇昂揚,領受天命的戰士啊
哪怕早已遍體鱗傷;哪怕早已竭盡氣力
熾熱地燃燒、壯烈地綻放這獻予上天的生命
獻上此身成為明日和平的堅固基石
將這猶如明星般的生命,熱血地燃燒、璀璨地殞落吧
這個名字定將穿越時空,銘刻於人們心中,直至永恆
英文歌詞 English Lyrics :
Rise up, Stay noble, warriors who have accepted heaven's mandate
Thousand resolutions, bound to your body, oh you, bravely thrust forth
A bell heralding an age of darkness rings far away
Comrades, now, you fear not even death
A destroyed city stained by the setting sun red
To protect this beloved earth's future
Oh, God's blade is humanity's love
Filled with prayers, pierce !
Rise up, Stay noble, warriors who have accepted heaven's mandate
Become the foundations towards tomorrow's peace
Become fervent, bloom greatly, lives offered to the heavens
Become the shield of the weak, and, lead the world
Floating in the shining sea of stars, your image
For a love you will never meet again, still beloved
Back to back with the world, an unmatching reality
Throw them away along with tears, everything
Come on, don't look back, be the wind
Surpass the pain and run !!
Rise up, Stay noble, warriors who have accepted heaven's mandate
Even if hurt and exhausted
Burn red, scatter grandly, lives who became stars
Overcoming time, we'll brand those names into our hearts, Just Forever
Rise up, Stay noble, warriors who have accepted heaven's mandate
Even if hurt and exhausted
Become fervent, bloom greatly, lives offered to the heavens
Become the foundations towards tomorrow's peace
Burn red, scatter grandly, lives who became stars
Overcoming time, we'll brand those names into our hearts, Just Forever
be bound for 在 ロイドごはん Youtube 的精選貼文
千葉で話題の煮干しラーメンのお店!『池田です!』に伺いました。以前、船橋市・東海神にて「零一弐三(すうじ)」をやられていた方のお店で、基本は屋号がない形で営業されているとのこと(食べログなどでは「池田です!」の名前で掲載されています)。看板がないお店にも関わらず、評判を聞きつけたラーメンファンが連日並ぶほどカルト的な人気とも言える話題店。麺の大盛りができたりいろいろ検索する流れの中で二郎系の文字が散見されますが、そういった名称にとらわれないオリジナルの味わいが魅力でした。個性的が光る1杯、早速ご覧ください!
*感染対策を徹底して撮影を行っています。
*撮影に際しては、お店の方や周りのお客様に充分配慮して撮影をおこなっています。
Niboshi ramen shop that is a hot topic in Chiba! "I'm Ikeda! I asked. Previously, it was a shop for those who had been doing "Reiichi Nisan" in Funabashi City, Higashikaijin, and it is said that it is basically open without a shop name ("Ikeda" in Tabelog etc. It is posted under the name of "It is!"). Despite the fact that there is no signboard, it is a hot topic store that can be said to be cult-like so popular that ramen fans who heard its reputation line up every day. Jiro characters are sometimes found in the process of making a large serving of noodles and searching variously, but the original taste that is not bound by such names was attractive. Please have a look at the unique cup!
* We take thorough measures against infection.
* When shooting, we give due consideration to the shop and customers around us.
いつもありがとうございます!( ´ ▽ ` )
高評価&チャンネル登録もよろしくお願いいたします!
#ラーメン #煮干しラーメン #千葉 #ロイドごはん #フラメンコロイド
—————《サブチャンネル》—————————————
【サブチャンネルもよろしくお願いします!】
メロンシートジャーニー
https://www.youtube.com/channel/UCwNlBAUziFWkJZFY_u3t65A
フラメンコロイド
https://www.youtube.com/channel/UCsFJHNg3SR41R2a3vctUInw
🍀「ロイドごはん」公式LINE
https://lin.ee/ow4OdaV
—————《本日の店舗情報》—————————————————
『池田です!』
https://tabelog.com/chiba/A1201/A120101/12051011/
—————《ロイドごはんのおすすめ動画 ROIDGOHANs’ Recommended video》———————————
・煮干しラーメン(青森)
史上最強ラーメン【中華そば田むら】本当にうまいラーメンを完飲完食
https://youtu.be/pg0LHZE-6BY
千葉県 【グルメ旅】
https://youtube.com/playlist?list=PL6yW17uB9uIX3_EZCcsvwE-mch09dSV8s
78才おじいちゃん屋台ラーメンの朝『幸っちゃん』夜明けの銀座 【飯テロ】Old Style Ramen yatai Japanese Street Food
https://youtu.be/YHiWYvhxUI4
【家系ラーメン特集!】
https://www.youtube.com/playlist?list=PL6yW17uB9uIVUmOS8qnXrRwcBu8W-uRYZ
—————《twitter》—————————————————————
★ロイドごはん
https://twitter.com/roidgohan
★メロンシート
https://twitter.com/meloncito310
★フラメンコロイド
https://twitter.com/flamenkoroid
—————《instagram》———————————————————-
★ロイドごはん
https://www.instagram.com/roidgohan
★メロンシート
https://www.instagram.com/satoshimelo...
★フラメンコロイド
https://www.instagram.com/flamenkoroid
—————《各サイトの情報》—————————————————
★ロイドwalker《人生をドラマチックに彩る旅とグルメと温泉図鑑》
https://ramenjapan.net/
★メロンシート《フラメンコギターの世界一の旅》
https://pordiotama3.xsrv.jp
★フラメンコロイド 《フラメンコロイドの神話と伝説》
https://flamenkoroid.net
be bound for 在 Nicole Chang Youtube 的最讚貼文
Finally got my Mom back on my channel ? Always wanted to find out how well she actually knows me, will she ace this challenge? Watch to find out, Happy Mother's Day! Ana Luisa is the perfect treat/gift and they are currently running an exclusive Mother's Day Sale!
Get 15% off all products: https://www.analuisa.com/nicolecmd
There's bound to be something that catches your eye ? #analuisany
Studio: @hoppitystudio
Get to know me better at:
Instagram: https://www.instagram.com/nicolechangmin
Facebook: https://www.facebook.com/nicolechangminofficial
TikTok: @nicolechangmin.raw
Second IG: https://www.instagram.com/nicolechangmin.raw
Website: https://www.nicolechangmin.com
Wanna be featured in my videos? Pop me an email at: nicolechangmin@gmail.com
(for collaboration/advertising opportunities)