📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有1040部Youtube影片,追蹤數超過14萬的網紅KAITV 小凱老師影音頻道,也在其Youtube影片中提到,時下妝容必備的修容步驟,可以讓你雕塑出立體精緻的五官輪廓~但依然很多人不知道也很害怕修容,不知道應該修哪裡,下多重,什麼時候用修容膏,什麼時候用修容粉?今天凱咪就要解開你的疑惑,讓你不在害怕修容! 👇今天用了它們👇 1. Makeup By Mario | Softsculpt Shaping S...
「highlighting」的推薦目錄:
- 關於highlighting 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於highlighting 在 Culture Trip Facebook 的最佳貼文
- 關於highlighting 在 小凱老師 Facebook 的最佳解答
- 關於highlighting 在 KAITV 小凱老師影音頻道 Youtube 的最佳解答
- 關於highlighting 在 channel Shii Youtube 的精選貼文
- 關於highlighting 在 西川 瑞希 Youtube 的最佳解答
- 關於highlighting 在 Fish shell like syntax highlighting for Zsh. - GitHub 的評價
- 關於highlighting 在 【技能樹栽種】實作CSS 凸顯文字內容: Alert 與Highlighting 的評價
highlighting 在 Culture Trip Facebook 的最佳貼文
It’s the personal touches hat makes this hotel so special. This swiftly becomes evident at check-in when guests are gifted hand-drawn neighborhood map, highlighting a selection of the area’s best attractions. The perfect spot if you want to get a feel for Puerto Rico but still indulge in wellness-focused little luxuries - one of of the hotels we 💚
highlighting 在 小凱老師 Facebook 的最佳解答
【凱學院】新手修容必看教學!質地選用、修容位置,一次搞懂!
時下妝容必備的修容步驟,可以讓你雕塑出立體精緻的五官輪廓~但依然很多人不知道也很害怕修容,不知道應該修哪裡,下多重,什麼時候用修容膏,什麼時候用修容粉?今天凱咪就要解開你的疑惑,讓你不在害怕修容!
👇今天用了它們👇
1. Makeup By Mario | Softsculpt Shaping Stick #Light Medium
2. Pat McGrath | Skin Fetish : Sublime Perfection Highlighting Brush
3. Etude | 修飾專家雙色修容餅 #2
4. KAIBEAUTY | 訂製輪廓刷 #F03
5. KKW Beauty | Brightening Powder #1
⭕️別忘了訂閱頻道⭕️開啟小鈴鐺🔔
➡️記得關注我的IG唷!
------------------------------
IG: https://www.instagram.com/kai_makeup_/
highlighting 在 KAITV 小凱老師影音頻道 Youtube 的最佳解答
時下妝容必備的修容步驟,可以讓你雕塑出立體精緻的五官輪廓~但依然很多人不知道也很害怕修容,不知道應該修哪裡,下多重,什麼時候用修容膏,什麼時候用修容粉?今天凱咪就要解開你的疑惑,讓你不在害怕修容!
👇今天用了它們👇
1. Makeup By Mario | Softsculpt Shaping Stick #Light Medium
2. Pat McGrath | Skin Fetish : Sublime Perfection Highlighting Brush
3. Etude | 修飾專家雙色修容餅 #2
4. KAIBEAUTY | 訂製輪廓刷 #F03
5. KKW Beauty | Brightening Powder #1
⭕️別忘了訂閱頻道⭕️開啟小鈴鐺🔔
➡️記得關注我的IG.FB粉絲專頁唷!
-----------------------------
IG: https://www.instagram.com/kai_makeup_/
FB: https://www.facebook.com/kaimakeuptw/
highlighting 在 channel Shii Youtube 的精選貼文
こんにちは♡Shioneです!
今回はコーラルメイクのチュートリアルです♡
私のチャンネルではメイク・ファッション・ネイル・購入品・お気に入りのアイテムなど私の好きな物やオススメのアイテムなどを動画で紹介しています♡
SNSもたくさん更新しているので是非見てみてください♡
お洋服も作ってます♡
Libecka
・ショップURL♡
https://muuu.com/brand/libecka/
楽天ROOM
https://room.rakuten.co.jp/room_466cd519a3/items
・FOLLOW ME
https://followme.app/@Shii__
・ラロッシュポゼ UVイデアXL プロテクショントーンアップ ローズ ¥3,740
https://amzn.to/3mtcB0s
・media クリームファンデーション OC-D1 ¥1,100
https://amzn.to/3fkkvFc
・elf HDリフティングコンシーラー Fair
・プリマヴィスタ 化粧もち実感おしろい ¥3,630
https://amzn.to/3kcMSXi
・キャンメイク カラーチェンジアイブロウ 06 ¥550
https://amzn.to/2XSvoIv
・URGLAM スリムスケッチアイブロウペンシル BR-2 ¥110
・rom&nd ベターザンパレット 01 ¥2,900
https://www.qoo10.jp/su/1294306240/Q110475660
・コージー アイラッシュカーラー ¥368
https://amzn.to/2WcWWYI
・KATE ラッシュマキシマイザー ¥1,320
https://amzn.to/3jaobeU
・MAC スタジオフィックス スカルプト&シェイプ コントアーパレットライト/ミディアム ¥7,370
https://www.maccosmetics.jp/product/13845/60431/makeup/studio-fix-sculpt-and-shape-contour-palette-lightmedium
・wetnwild coloricon BLUSH Pearlescent Pink ¥392
https://iherb.co/5WJEegS
・BOBBI BROWN ハイライティングパウダーデュオ L01 ピーチグロウ ¥6,600
https://www.bobbibrown.jp/product/14022/87754/highlighting-powder-duo#/shade/L01_ピーチグロウ
・MAC テクナコール グラフブラック
・NARS ハイピグメントロングウェアアイライナー 8194 ¥3,300
https://www.narscosmetics.jp/high-pigment-longwear-eyeliner/E49901.html?dwvar_E49901_color=8190&cgid=eyeliners
・キャンメイク クリーミィタッチライナー 05 ¥715
https://amzn.to/3kgO6B3
・TooFaced ベターザンセックスマスカラ ウォータープルーフ ¥3,300
https://www.toofacedcosmetics.jp/product/23484/59117/better-than-sex-waterproof/waterproof-mascara/Better-Than-Sex-Waterproof
・MAC パウダーキスリップスティック ブリックスルー ¥3,520
https://www.maccosmetics.jp/product/13854/60284/makeup/powder-kiss-lipstick#!/shade/ブリックスルー
・KATE ディメンショナルルージュ PK-1 ¥1,320
https://amzn.to/3mqdU0j
・ミッシュブルーミン スモーキーマロン ¥1,760
https://amzn.to/2XI7NtO
・SHEIN ギンガムチェックシャツ ¥1,445
https://jp.shein.com/DAZY-カジュアル-ボタンフロント-ギンガム-ブラウス-p-2456744-cat-1733.html
・selectshoptii チェリークォーツ ピアス ¥1,800
https://minamong.shopselect.net/items/50917302
楽曲提供:Production Music by http://www.epidemicsound.com
#コーラルメイク #海外コスメ #フルメイク
・ショップURL♡
https://muuu.com/brand/libecka/
herb URL
http://jp.iherb.com/?rcode=QFL562
instagram
http://instagram.com/shione__1101/
twitter
http://twitter.com/Kuualoha_s
highlighting 在 西川 瑞希 Youtube 的最佳解答
今回は秋の新作コスメをつかって、メイクをしました🌾
ほんとーに、全部かわいすぎて毎回使うのが楽しみ//
今季はモードでちょっぴり暖かみのあるカラーが多め!くすみカラーすぎにはたまりません♡
参考になれば嬉しいです!
ONE PIECE...
https://www.cheriemona.jp/fs/cheriemona/80215603
【DIRECTOR/PRODUCER】
▪︎Cherie Mona
https://www.cheriemona.jp/ec/sp/
▪︎MIiI
https://miii-shop.jp/
【SNS】
▪︎OFFICIAL SALON
https://mizuki-nishikawa.com
▪︎Instagram
https://www.instagram.com/mizuki_nishikawa_/
▪︎Twitter
https://twitter.com/mizukitty921116
▪︎LINE BLOG
https://lineblog.me/mizukitty/
【Cosmetics used】
▷ネイル
[RMK]Lipstick Comfort Airy Shine
EX-04 ムーディーモーヴ / ¥3,850
▷アイシャドウ
[bareMinerals]MINERALIST Eyeshadow palette
SUNLIT / ¥5,280
▷アイライナー
[bareMinerals]MINERALIST Lasting Eyeliner
Topaz / ¥2,750
▷チーク&ハイライト
[BOBBI BROWN]Highlighting powder duo
Color:L01 Peach glow
¥6,600
▷リップ
[RMK]nail polish
EX-43 レッドクレイ ¥1,650
00:00 オープニング
01:29 ネイル
01:59 アイシャドウ
05:35 アイライン
07:13 チーク&ハイライト
08:31 リップ
#秋メイク
#新作コスメ
#メイク動画
highlighting 在 【技能樹栽種】實作CSS 凸顯文字內容: Alert 與Highlighting 的推薦與評價
【技能樹栽種】實作CSS 凸顯文字內容: Alert 與Highlighting. 2021-03-11 | 網誌設定與開發 , 程式語言與架構 | | 4. 我目前Github Page 採用的主題 ... ... <看更多>
highlighting 在 Fish shell like syntax highlighting for Zsh. - GitHub 的推薦與評價
It enables highlighting of commands whilst they are typed at a zsh prompt into an interactive terminal. This helps in reviewing commands before ... ... <看更多>