📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有353部Youtube影片,追蹤數超過2萬的網紅黑小多,也在其Youtube影片中提到,《黑小多のTwitch實況台》←“頻道相關Q&A”也在這邊看唷~ http://www.twitch.tv/blackchan 《黑小多の粉絲團》←大家趕緊去幫我按個讚吧!w http://www.facebook.com/heyxiaotto 《能貓姊整理的全成就資料》←感謝能貓姊! http...
「high enough」的推薦目錄:
high enough 在 Mia's手作料理 Facebook 的最佳貼文
以蒜頭、鯷魚、羅勒、檸檬汁和堅果,拌入品質優質橄欖油和帕馬森起司手工製成 ,相信大家對青醬並不陌生,但手工製作的青醬你一定要試試 ! 先炒過你喜歡的肉類、海鮮或蔬菜,在加入青醬,無論配上義大利麵、燉飯或者Gnocchi都很適合 ! 很推薦使用蛤蠣或其他海鮮,能夠襯托鮮味!
手工做的青醬較濃稠,需要加入煮麵水讓醬變稀釋(大約150cc),也可看個人調整決定,若是煮海鮮或燉飯,可加入一般清水或高湯自行稀釋至喜歡的濃度 ,做千層麵或抹土司不需要兌水。
Handmade with garlic, anchovies, basil, lemon juice and nuts, mixed with high-quality olive oil and Parmesan cheese. I believe no-one is a stranger to pesto, but you must try our handmade one, it makes a world of difference! Fry your favorite meat, seafood, or vegetables first, then toss them in our pesto and serve it with pasta, risotto, or gnocchi. Try pairing it with clams or other seafood to really bring out that delicious umami flavor!
Our handmade pesto is thicker than usual, so you will need to reserve some pasta water and add it to the sauce to dilute it (around 150cc should do, but you can adjust the amount according to personal preference!). If you are making seafood or risotto, you can add water or stock until it is diluted enough to suit your taste. There is no need to add water to make lasagna or spread it on toast!
#miahomemadefood #mia手作料理 #青醬 #pesto #homemadepesto #homemade #手工青醬 #自製青醬
high enough 在 Beast Runners 跑山獸 Facebook 的最佳解答
[New Video 新影片] LET`S GET WET | 水上瀑布 | 澀水森林步道
https://youtu.be/NzwpvggqAdw
Here if proof that even two adult men can play like small kids and have happy time.
We had lot of fun in my favourite area in stream of 澀水森林步道. Our family loves come here for the trail walk and play water.
in video can see:
💧 Tom sitting on but after great fall
💧 Petr jumping and climbing and laughing
💧 awesome 水上瀑布 Shuishan waterfall
💧 see how high speed run of Beast Runners 跑山獸 looks like in river
💧 if you are lucky enough you will spot Bamboosaur 🦖
💧 weird sound in water...
💧 got black passanger, lazy bumblebee 🐝
💧 lot water and fun...
LET`S GET WET and enjoy the video as we did
high enough 在 黑小多 Youtube 的最佳解答
《黑小多のTwitch實況台》←“頻道相關Q&A”也在這邊看唷~
http://www.twitch.tv/blackchan
《黑小多の粉絲團》←大家趕緊去幫我按個讚吧!w
http://www.facebook.com/heyxiaotto
《能貓姊整理的全成就資料》←感謝能貓姊!
https://docs.google.com/spreadsheets/d/1j7JMNRIhwuwFZFctuVALVUztkkWgeQjFT_vTaHvW9Ts/edit?usp=sharing
----------------------------------------------------
0:00 需要通關的關卡
0:41 彈鋼琴
-----57個所需成就-----
1:46 1.Jewelry Store 珠寶店 - Diamonds are Forever
1:52 2.任何銀行劫案 - A Good Haul
1:57 3.Shadow Raid 影之襲擊 - I Will Pass Through Walls
2:02 4.GO Bank 全武銀行 - All Eggs in One Basket
2:07 5.Diamond Store 鑽石店 - Hostage Situation
2:25 6.任何運鈔車劫案(不包含火車) - But Wait - There’s More
2:36 7.Train Heist 運鈔車:火車劫案 - We’re Gonna Need a Bigger Boat
2:44 8.Mallcrasher 商場破壞者 - Self Checkout
2:48 9.Four Stores 四間店 - Platinum Card 或 Yeah, He’s a Gold Digger
2:53 10.White Xmas 白色聖誕劫- What’s in the Box?
2:56 11.Ukrainian Job 烏克蘭人的委託 - Let’s do th…
3:01 12.Meltdown 爐心熔解 - They Don’t Pay Us Enough
3:08 13.Aftershock 震後餘生 - Bring It Back Safe
3:17 14.Nightclub 夜總會 - Let Them Boogie
3:30 15.Stealing Xmas 聖誕大盜 - The Grinch
3:39 16.Watchdogs 看門狗 - Out of bounds
4:06 17.Firestarter 縱火者 - Lord of War
4:13 18.Rats 鼠輩 - Full Measure
4:19 19.Big Oil 石油大亨 - Doctor Fantastic
4:28 20.Framing Frame 偷天換日 - I Wasn’t Even There!
4:38 21.Election Day 選舉日 - I’m A Swinger
4:48 22.Big Bank 大銀行 - Don’t bring the Heat
4:59 23.Hotline Miami 熱線邁阿密 - Walk Faster
5:16 24.Hoxton Breakout 老哈逃獄記 - Watch The Power Switch!
5:22 25.Hoxton Revenge 老哈復仇記 - Silent But Deadly
5:30 26.The Diamond 驚世奇鑽 - Cat Burglar
5:37 27.Golden Grin Casino 金牙賭場劫案 - High Roller
5:52 28.Bomb: Dockyard 炸彈劫案:碼頭 - I’ve got the Power
6:06 29.Bomb: Forest 炸彈劫案:森林 - Pump It Up
6:20 30.Scarface Mansion 疤面公館 - Settling a Scar
6:28 31.The Alesso Heist 音樂會劫案 - Sound of Silence
6:39 32.Counterfeit 偽鈔風雲 - Dr. Evil
6:48 33.First World Bank 世界第一銀行 - OVERDRILL
6:54 34.Murky Station 黑水火車站 - The Pacifist
7:06 35.Boiling Point 沸點 - Remember, No Russian
7:22 36.Goat Simulator 山羊模擬器 - Hazzard County
7:49 37.Santa’s Workshop 聖誕工坊 - Santa Slays Slackers
8:11 38.Car Shop 車店 - Gone in 240 seconds
8:19 39.The Biker Heist 暴走族劫案 - Full Throttle
8:37 40.Panic Room 戰慄空間 - Quick Draw
8:48 41.Brooklyn 10-10 荒唐警局 - A Rendezvous With Destiny
9:04 42.The Yacht Heist 遊艇劫案 - Pacifish
9:11 43.Undercover 骯髒交易 - Not Even Once
9:29 44.Slaughterhouse 屠宰場 - Making a Statement
9:47 45.Beneath the Mountain 山脊之下 - Clean House
10:12 46.Birth of Sky 誕於天際 - 1...2...3… JUMP!
10:25 47.Heat Street 熱街 - It’s Nice To Be Nice
10:39 48.Green Bridge 格林大橋 - Attacked Helicopter
10:49 49.Alaskan Deal 阿拉斯加交易- The Fuel Must Flow
10:59 50.Diamond Heist 經典鑽石劫案 - Blood Diamond
11:13 51.Reservoir Dogs 落水狗劫案 - Waste Not, Want Not
11:27 52.Brooklyn Bank 布魯克林銀行- All the Gold in Brooklyn
11:36 53.Breakin’ Feds 闖越FBI - Stalker
12:08 54.Henry’s Rock 亨利峽谷 - Hack This!
12:22 55.Shacklethorne Auction 拍賣會劫案 - Press [F] to pay Respect
12:47 56.Hell’s Island 地獄島 - Beacon of.. nope
12:55 57.No Mercy 慈愛醫院 - Keeping the Cool
13:15 結語
------------------------------------------------------------------------------------------------
如果你喜歡我的Youtube影片,記得在影片左下方的地方按一下「喜歡」的按鈕,
以及「訂閱」我的Youtube,訂閱我的頻道就能與小多簽訂暗黑契約,
亦或是在下面留下你的評論,你的評論也可以讓小多的暗黑力量繼續壯大唷!(ˋ wˊ)/
#黑小多
#劫薪日2
#隱藏結局
![post-title](https://i.ytimg.com/vi/r0hWFpivKd8/hqdefault.jpg)
high enough 在 Hashimoto Shun Youtube 的最佳貼文
Heal this crazy, but lovely world for us.
Love yourself:)
Instagram: https://instagram.com/hashi__shun
Twitter: https://twitter.com/Sh__gtm
There's a place in
your heart
and I know that it is love
and this place could
be much
brighter than tomorrow
and if you really try
you'll find there's no need
to cry
in this place you'll feel
there's no hurt or sorrow
there are ways
to get there
if you care enough
for the living
make a little space
make a better place...
Heal the world
make it a better place
for you and for me
and the entire human race
there are people dying
if you care enough
for the living
make a better place
for you and for me ah
If you want to know why
there's a love that
cannot lie
love is strong
it only cares of
joyful giving
If we try we shall see
in this bliss
we cannot feel
fear or dread
we stop existing and
start living
then it feels that always
love's enough for
us growing
So make a better world
make a better world...
Heal the world
make it a better place
for you and for me
and the entire human race
there are people dying
if you care enough
for the living
make a better place
for you and for me
And the dream we were
conceived in
will reveal a joyful face
and the world we
once believed in
will shine again in grace
then why do we keep
strangling life
wound this earth
crucify its soul
though it's plain to see
this world is heavenly
be god's glow
we could fly so high
let our spirits never die
in my heart
I feel you are all
my brothers
create a world with
no fear
together we cry
happy tears
see the nations turn
their swords
into plowshares
we could really get there
if you cared enough
for the living
make a little space
to make a better place...
Heal the world
make it a better place
for you and for me
and the entire human race
there are people dying
if you care enough
for the living
make a better place
for you and for me
Heal the world
make it a better place
for you and for me
and the entire human race
there are people dying
if you care enough
for the living
make a better place
for you and for me
Heal the world
make it a better place
for you and for me
and the entire human race
there are people dying
if you care enough
for the living
make a better place
for you and for me
there are people dying
if you care enough
for the living
make a better place
for you and for me
there are people dying
if you care enough
for the living
make a better place
for you and for me
you and for me
#Healtheworld
#弾き語り
#cover
![post-title](https://i.ytimg.com/vi/lk2eoo-wadc/hqdefault.jpg)
high enough 在 kottaso cook【kottaso Recipe】 Youtube 的精選貼文
◆こっタソ動物園チャンネル
新しいチャンネルです!こちらもおヒマな時にどぞ。
⇒https://www.youtube.com/c/こっタソ動物園-kottasoanimals
ご視聴ありがとうございます。
Thank you for watching
I want to deliver delicious Japanese-food recipes to the world
【材料】
●もやし:2袋(400g)
●牛豚の合挽き肉:約300g(豚挽肉だけでもOK)
●コチュジャン:大さじ2.5(豆板醤でもOK)
●醤油:大さじ1
●砂糖:大さじ1(ラカントにすると更に糖質抑えられます)
●オイスターソース:大さじ1
●みりん:大さじ1
●お酒:大さじ1
●にんにく:小さじ1/2
●生姜:小さじ1/2
●ごま油
●塩コショウ少々
●最後にブラックペッパー
お好みで万能ねぎ、ラー油、韓国唐辛子、一味唐辛子
※グラム数を同じくらいにしてお肉や野菜を変更しても美味しいよ♪
※辛いのが苦手な方はコチュジャンの量を減らして普通の味噌を足してあげて下さい。
※もやし入れたら強火で2~3分くらいでOK(量が少なかったらもっと短くても大丈夫)
※もやしのひげ根は栄養があるので気にならない方はとらなくても大丈夫です。
-------------------------------------------------------
食べれば食べるほどハマる…悪魔的旨辛『悪魔の肉もやし』作りました。
これあると、ご飯、お酒、ラーメンが鬼すすみます🤤
糖質制限されている方は肉もやしだけでも十分お腹一杯になりますよ。
残ったタレをご飯にぶっかけて食べても最高に旨いよ♪
たった5分炒めるだけの超簡単なレシピになっているので
是非作ってみて下さい。
[Ingredients]
● Bean sprouts (400g): 2 bags
● Ground beef and pork: about 300g (ground pork alone is also OK)
● Gochujang (soybean paste): 2.5 tablespoons
● Soy sauce: 1 tablespoon
● Sugar: 1 tablespoon (you can use LACANTS to further reduce sugar content)
● Oyster sauce: 1 tablespoon
● Mirin: 1 tablespoon
● Sake: 1 tablespoon
● Garlic: 1/2 teaspoon
● Ginger: 1/2 teaspoon
● Sesame oil
● A pinch of salt and pepper
● Black pepper at the end
Optional: scallions, Ra-yu, Korean chili pepper, cayenne pepper powder
※ You can use the same number of grams and change the meat and vegetables.
※ If you don't like spicy food, you can reduce the amount of gochujang
and add regular miso.
※ After adding the bean sprouts, cook on high heat for about 2~3
minutes. (If the amount is less, you can make it shorter.)
※ The beard root of bean sprouts is nutritious, so you don't need to
remove it if you don't mind.
-------------------------------------------------------
The more you eat, the more you become addicted... I made a devilishly
delicious and spicy "Devil's Meat & Bean Sprout'."
It's a great way to enjoy rice, drinks, and ramen!
If you are on a carbohydrate restriction diet, this menu alone will be
enough to fill you up.
You can also pour the leftover sauce over rice and eat it ♪
This is a very simple recipe that only takes 5 minutes to fry, so
please try making it.
●Instagram
⇒https://www.instagram.com/kossarishuntaso/
●twitter
⇒https://twitter.com/kottaso_recipe
●連絡先
⇒kossarisyuntaso@gmail.com
#こっタソの自由気ままに #悪魔の肉もやし #無限もやしユッケ #もやしレシピ #ひき肉レシピ #BeanSprouts #豆芽 #JapaneseCuisine #DevilsSauce #HealthyMenu #LowCarbDiet #숙주 #저당질 #악마의양념 #和食 #低糖質おつまみ #糖質制限レシピ #ヤセ筋 #低糖質レシピ #ヘルシー #ダイエットレシピ #激痩せ #ロカボレシピ #dietfood #lowcarbdiet #dietrecipe #晩ごはんレシピ #ご飯泥棒 #おかず #極上レシピ #ワンパンレシピ #時短レシピ #おうちごはん #至福の料理 #ご飯のお供 #太らないレシピ #やみつきレシピ #酒のつまみ #簡単つまみ #こっタソレシピ #男飯レシピ #mukbang #먹방 #男子ごはん #HomeCooking #StayHome #大食い #男ウケ料理 #晩酌 #自炊 #酒の肴 #簡単レシピ #弁当 #作り置き #Bento #recipesfordinner #マツコの知らない世界 #WithMe #Eazyrecipe #モッパン #から揚げ #唯一無二の絶品レシピ #こっタソ動物園
![post-title](https://i.ytimg.com/vi/mBsnSgMuUxo/hqdefault.jpg)