📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有775部Youtube影片,追蹤數超過24萬的網紅Square Enix,也在其Youtube影片中提到,Play Marvel’s Guardians of the Galaxy on an NVIDIA GeForce RTX PC to experience high levels of fidelity, real-time ray tracing, NVIDIA DLSS’ AI-powere...
「high performance」的推薦目錄:
- 關於high performance 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於high performance 在 EE Times Taiwan Facebook 的最佳解答
- 關於high performance 在 REEF OMAR Facebook 的最佳貼文
- 關於high performance 在 Square Enix Youtube 的最佳貼文
- 關於high performance 在 Nini Music Youtube 的最讚貼文
- 關於high performance 在 GKJUMPMAN Youtube 的最佳解答
- 關於high performance 在 HP-High Performance - 首頁| Facebook 的評價
high performance 在 EE Times Taiwan Facebook 的最佳解答
從Intel、微軟透露的資訊可知的是,Alder Lake + Windows 11,實現了硬體級的調度回饋機制,與此同時Windows 11能夠基於這種回饋來實現完全「動態」的調度…
https://www.eettaiwan.com/20210922nt61-alder-lake-and-windows-11-make-high-performance/
high performance 在 REEF OMAR Facebook 的最佳貼文
Barulah stailo!
Orang lelaki kenalah jaga penampilan biar kemas dan rapi. Sebab itu kena ada REMINGTON Pro Power Precision Steel Hair Clipper dekat setiap rumah supaya senang nak trim rambut, janggut dan misai!
Best sangat ke benda ni?
➡️Pro Power Motor for 2 x cutting performance.
➡️Advanced Blade Geometry maximises cutting efficiency to cleanly cut hairs.
➡️17 lenght setting ranging from 0.5 - 44mm for different hair styles.
➡️Stainless steel blades with high quality and durable steel blades.
➡️SlideSelect adjustor combs with auto lock.
➡️Corded and cordless usage option.
➡️Charging LED indicator.
➡️2 years domestic warranty.
Best kan? Berbaloi beli! Beli disini: https://mystyle.60sec.asia/ack/niFAaBykvR
Jangan lupa guna kod promo INNORO10 untuk harga istimewa!
#60sec
#FMCOpromo
#socialcommerce
#Remington
high performance 在 Square Enix Youtube 的最佳貼文
Play Marvel’s Guardians of the Galaxy on an NVIDIA GeForce RTX PC to experience high levels of fidelity, real-time ray tracing, NVIDIA DLSS’ AI-powered performance boost, diffuse illumination, HDR and wide color gamut, and up to 8K resolution.
Marvel's Guardians of the Galaxy is coming October 26 to PC and streaming via GeForce NOW. Pre-order now to obtain an early unlock of the Throwback Guardians Outfit Pack: http://www.gotggame.com/buy
Follow us on:
Facebook: https://www.facebook.com/GOTGTheGame
Twitter: https://www.twitter.com/GOTGTheGame
Instagram: https://www.instagram.com/GOTGTheGame
high performance 在 Nini Music Youtube 的最讚貼文
My collab with @Ban Brothers for their New Track "Dream High"
Join My Patreon + Get your own cover: https://www.patreon.com/ninimusic
Download My Music (for free): https://ninimusic.bandcamp.com/releases
♬Stream It ▹
► Spotify: https://spoti.fi/3pw57Jl
► Apple Music: https://apple.co/3nr0AWH
♬SUPPORT ▹ Venmo/Cashapp: ninimusic
paypal.me/ninimusic1001 or ninimusic1001@gmail.com
♬FOLLOW ME ▹ Inst- http://instagram.com/ninimusic1001
FB- https://www.facebook.com/NINIMUSIC1001/
Bookings and Other Questions: ninimusic1001@gmail.com
Title: Dream High
[First Release from EP/Album: Guiding Star - songs of "hope, inspiration, and love"]
Original Artist: Ban Brothers
Cover (San Xian): Nini Music
Producer: Ban Brothers with Sundown Sessions Studio
Recording Engineer, Mixing, and Mastering: Sundown Sessions Studio
Executive Producer: Swagata "Ban" Banerjee (of Ban Brothers)
Writer, Composer, and Arranger: Swagata "Ban" Banerjee (of Ban Brothers)
Publisher: Ban Brothers Publishing
Performance Rights Organization: ASCAP
Distributor: CD Baby
Label: Ban Brothers
Date of Release: September 10, 2021
#ninimusic #sanxian #banbrothers #newmusic #shamisen #kickstarter #twitch #live #traditionalinstrument #folkinstrument #erhu #snakeskininstrument
high performance 在 GKJUMPMAN Youtube 的最佳解答
2021年9月に発売されるエアジョーダンとナイキを紹介していきます!
収集した情報を精査してまとめておりますが、
COVID-19の影響により発売日のズレや延期が生じております。
また、海外のサイトや過去の価格を参考にしておりますので、
価格に誤差があるかもしれません。
軽い気持ちで参考程度にご覧ください!
そして、みなさんが楽しんでいただければと思います。
Hey what's up everybody? It's GKJUMPMAN.
This video is about the Air Jordan & Nike releases in August, 2021.
*The estimated release dates are for Japan.
Hope you like this video, please enjoy!!!
●9月リリース予定
・9月1日:
Nike LeBron 18 Low (19,250円)
Quartersnacks x Nike SB Dunk Low ($110)
・9月2日:
Nike Air Max 96 II (19,250円)
Nike Air Force 1 LUX (15,400円)
・9月3日:
Nike LeBron 18 Low “Sylvester vs Tweety” (19,250円)
Nike KD 14 (19,250円)
Nike ACG Air Mowabb (19,250円)
・9月4日:
Air Jordan 6 Retro “Bordeaux” (23,100円)
Jordan Series .02 (8,800円)
Social Status x Nike Dunk Mid ($130)
・9月8日:
Air Jordan 1 KO “Storm Blue” (17,050円)
・9月9日:
Billie Eilish x Air Jordan 1 KO (???)
Billie Eilish x Air Jordan 15 (???)
・9月10日:
Air Jordan 1 Retro High OG (19,250円)
Nike Zoom Freak 3 (14,850円)
Nike Dunk High EMB ($110)
・9月13日:
Nike Zoom Freak 3 (14,850円)
・9月18日:
Air Jordan 11 Retro Low IE (21,060円)
Air Jordan 13 Retro “Obsidian” (23,100円)
Social Status x Nike Dunk Mid ($130)
・9月23日:
Off-White x Air Jordan 2 Low (???)
・9月25日:
Air Jordan 5 Retro “Shattered Backboard” (23,100円)
🏀チャンネル登録はこちらから🏀
https://www.youtube.com/channel/UCaxG7u2dOgKbif7SsqBbsHA?sub_confirmation=1
🏀仕事関係の御連絡はこちらから🏀
[email protected]
===============================================
Resouces:
Sneaker News: http://sneakernews.com/
Sneaker Bar Detroit: https://sneakerbardetroit.com/
Nike+ SNKRS: https://www.nike.com/jp/launch/
===============================================
------------------------------------------------------------------------------
楽曲提供:Production Music by http://www.epidemicsound.com
------------------------------------------------------------------------------
ツイッター、インスタグラム、アメブロもやっていますので、フォローお願い致します!
Follow me on Twitter & Instagram!
・Twitter: https://twitter.com/gkjumpman
・Instagram: https://www.instagram.com/gkjumpman/
・Ameba Blog: http://ameblo.jp/gk-loves-sports/
#STAYSAFE #AirJordan #エアジョーダン #Nike #ナイキ
high performance 在 HP-High Performance - 首頁| Facebook 的推薦與評價
HP-High Performance 。 5675 個讚。千葉興業有限公司自1997年創立以來,一直秉持著「以客為尊」以消費者為中心的信念,並深耕於消費群之中,歷年來經過時間的沉澱、 ... ... <看更多>