📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有50部Youtube影片,追蹤數超過427的網紅yichiehdaily??,也在其Youtube影片中提到,Instagram:yichieh0830 本週highlight就是做芒果千層 我第一次切芒果就切到手....還兩手都切到 從下午四點做到晚上七點 那天晚上是我近期最早睡的一天 這次一直拖到星期六晚上才開始剪這部影片 凌晨兩點多才剪完上傳 原本想說拖到下禮拜再剪好了 但下禮拜就是期末考週 也是...
「pick up art」的推薦目錄:
- 關於pick up art 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於pick up art 在 Facebook 的最佳解答
- 關於pick up art 在 Benny Price Fitness Facebook 的精選貼文
- 關於pick up art 在 yichiehdaily?? Youtube 的最佳解答
- 關於pick up art 在 BarryChen Official Youtube 的精選貼文
- 關於pick up art 在 Dainghia25 Youtube 的最佳解答
- 關於pick up art 在 Pick-Up Art | Facebook 的評價
- 關於pick up art 在 31 Best Pickup Artist ideas | pick up lines, pick up ... - Pinterest 的評價
pick up art 在 Facebook 的最佳解答
As much as I’m an Hermes gal, I do love my Louis Vuitton 😍 Also need you guys to pick an art piece to be drawn onto my new handbag! My Louis Vuitton Collection is now up on my YouTube channel (link in bio) watch the full video to see my favourite pieces!
pick up art 在 Benny Price Fitness Facebook 的精選貼文
🇬🇧 London! I’m coming to town for a couple of weeks this month, and I’m so excited, I’m offering a ridiculous rate on personal training sessions 🙀 3 sessions for just £99 for the first 5 people that snap them up!
-
I’ll build you a personalised program right down to the perfect rep; completely customised and optimised exactly according to your personal goals, abilities and tolerances. We’ll get right down to the detail in exercise selection, design and technique to create a 6-10 week program - and then I’ll teach you the secrets to the art of sticking with it 🗓
-
Whether you want me to start a program from scratch or assess and optimise your current form, no matter your experience or fitness level, there is something we can work on 😉
-
Beginners: Getting more muscle for your hustle; learn how to choose the right exercise for maximum results 📈
Intermediate: Take your training up a level with the finer details of executing exercises 🧐
Advanced: High level cues to maximise contractions and squeeze that extra 5% out of every rep 💪🏽
-
You just pick the gym and cover the entry costs. Note: I’ll be based in Brixton, and any travel outside a 1-hr radius may incur a small additional fee 🚂
pick up art 在 yichiehdaily?? Youtube 的最佳解答
Instagram:yichieh0830
本週highlight就是做芒果千層
我第一次切芒果就切到手....還兩手都切到
從下午四點做到晚上七點
那天晚上是我近期最早睡的一天
這次一直拖到星期六晚上才開始剪這部影片
凌晨兩點多才剪完上傳
原本想說拖到下禮拜再剪好了
但下禮拜就是期末考週
也是「網課ㄉㄟˉ哩」的最後一集了
希望我可以成功達成一個月的週更👍🏻
“時間軸🌪“
0:00 Start✨
0:22 Day 1
1:50 Day 2
3:17 Day 3
5:20 Day 4
6:28 Day 5
10:45 The End
“𝙎𝙪𝙗𝙨𝙘𝙧𝙞𝙗𝙚 𝙢𝙮 𝙘𝙝𝙖𝙣𝙣𝙚𝙡 “
https://youtube.com/c/Tsaiyichieh
“𝘼𝙗𝙤𝙪𝙩 𝙢𝙚 “
Instagram | @yichieh0830
https://www.instagram.com/yichieh0830/
Picture’s acc | @cokercha_
https://www.instagram.com/cokercha_/
“𝙏𝙤𝙤𝙡𝙨 “
Camera | Canon G7X MarkII + Iphone11
Cover | Photoshop
“𝙈𝙪𝙨𝙞𝙘𝙨 “
art of worship - you're good to me - https://thmatc.co/?l=141DC414
Hayden McHugh - Smile - https://thmatc.co/?l=D1E15E12
Alexis Rice - Penny - https://thmatc.co/?l=97FFC154
pick up art 在 BarryChen Official Youtube 的精選貼文
數位收聽 🎧 http://barrychen.lnk.to/PTSAY
總會有那麼一首歌,陪伴你度過無數個失眠的夜晚
總會有那麼一首歌,在你失落徬徨時給你鼓勵替你鼓掌
總會有那麼一首歌,在你恐懼的時候給你勇氣
總會有那麼一首歌,在腦海裡久久揮之不去
音樂是生活的調劑、緊緊聯繫著我們的情緒
經過這一切的風風雨雨,按下播放鍵吧!
這一首歌的時間裡,有我給你力量,有我在這陪著你。
Barry Chen新曲『PTS』以輕鬆的節奏,彈跳的旋律
展現出樂觀進取的生活態度,沒有什麼事情是過不去的
體會人生的起起落落高高低低,如果心碎了
真的沒什麼大不了,把它給黏起來、生命依然要繼續。
就是現在,Play This Song and Everything will be alright。
#BarryChen
#PlayThisSong
_
■ Play This Song
詞曲:Barry Chen
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去 Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
他們都說你變了
過去對你的愛全不見了
Barry 從走到飛之後就墜了
沒有喝酒但也是醉了
Roll me a joint 謝了 我的 Yella
盪過谷底持續想上提升
答應自己今年再賺五個Million
媽媽不再擔心 Now I’m doing better
愛音樂的孩子不會變壞
跟隨自己的步伐跳得多麼自在
拿出自信成為自己理想的天菜
你能夠做到一次 就可以do it twice
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
心碎了 Pick it up
黏起來 We bounce back
想哭就哭想笑就笑
沒有什麼大不了
不小心跌倒 Stand up
撥掉身上的灰還是站得高
看著鏡子 Girl you look so fine
one two step 沒有 wrong or right
follow your heart 隨他怎麼看
the world is yours 等你來主宰
太多意見不想聽
戴上耳機享受自己
跳過陷阱超級瑪利
節奏是金幣 感受它的威力
Call out 妳的姊妹
帶上我的Whole crew
謝絕所有bad mood
加入一起跳舞
一首好歌能夠化敵為友
卸下武裝地球和平相處
每當你難過 Play This Song
每當你寂寞 Play This Song
每當你想起我 Play This Song
請記得抬起頭 Play This Song
去Night Club 跳個舞 很開心 Yeah
騎摩托 兜個風 煩惱不見
別害怕 有我在 陪你冒險
摔了跤 沒什麼 還有明天
心碎了 Pick it up
黏起來 We bounce back
_
演唱者 Performer:Barry Chen
作詞人 Lyrics:Barry Chen
作曲人 Composer:Barry Chen
製作人 Producer:Barry Chen/JO&H BEAT$ 王淳壹
編曲 Arrangement:JO&H BEAT$ 王淳壹
錄音室 Recording Engineer:JO&H BEAT$ 王淳壹
混音師 Mixing Engineer:JO&H BEAT$ 王淳壹
_
|影像製作|
製作統籌 黃景弘
導演 Director |豆子 Dozkuo
副導演 Assistant Director |陳杰 Jerry
製片 Producer|郭宥 Guo-Yow
執行製片 Line Producer |鄭伊真 Zheng-Yi-Zhen
製片助理 Production Assistant |謝渝茹 Yu Ju Heieh
製片實習生 Producer Intern|馬韡云 Vivian Ma
攝影師 D.O.P |豆子 Dozkuo、陳杰 Jerry
跟焦師 Focus Puller |王俊翔 Chun Hsiang Wang
攝影組 Camara Crew |吳士弘 Shih Hung Wu、廖奕婷 I-ting Liao
燈光師 Gaffer|林冠鐙 KT Lin
燈光助理 Best Boy |陳家閎 Chen Chia Hung、邱柏隆 Qio Bo Long
美術Art Designer |黃慈茵 Huang Tzu Yin
美術助理 Art Assistant |鄒慧琦 Chow Hui Qi
剪接 Editor |豆子Dozkuo
調光 TC|豆子Dozkuo
字卡 Typography |
【特別感謝 Special Thanks】
旋轉牧馬有限公司
詹浩數學資優補習班
猴子電場景
pick up art 在 Dainghia25 Youtube 的最佳解答
Conserving Ammunition Hitman 3 Dubai Assassinations Guide
recomend mastery level 15/20 unlock Agency Pickup Art Blackstage
Balcony ( Sniper Rifle Druzhina 34 dti)
timeline
4:29 Pick up Military Briefcase location
6:14 eliminate both with a single bullet using a sniper rifle
#hitman3 #hitman3dubaiconservingammuntion #hitman3conservingammunition
▶ SUBSCRIBE MY CHANNEL : https://goo.gl/VPOrGK
▶ RENUMBER LIKE, SUBSCRIBE AND SHARE MY VIDEO!!!
▶ Fanpage Facebook : https://www.facebook.com/dainghia25gaming
▶ Facebook : https://www.facebook.com/dainghia25
pick up art 在 31 Best Pickup Artist ideas | pick up lines, pick up ... - Pinterest 的推薦與評價
Sep 16, 2018 - the best pickup lines. See more ideas about pick up lines, pick up lines cheesy, pick up lines funny. ... <看更多>
pick up art 在 Pick-Up Art | Facebook 的推薦與評價
The Pick-Up Art Project is a journey, an experiment, a collection. It's a chance to make your mark in a group art project with total strangers. The first book ... ... <看更多>