📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有164部Youtube影片,追蹤數超過1萬的網紅translation,也在其Youtube影片中提到,#'90年にセガ第2AM研究開発部が開発、セガが稼働させた、AC用3DSTG作品。ゲームデザインは鈴木裕氏が担当。 難易度選択後、F-14風の機体・A8M5 MkII "ZEEK"に搭乗、バルカンとミサイルを駆使し、制限時間内に規定数の敵機を撃墜するとステージクリア。 BGMはHiro師匠と後輩の...
「unused」的推薦目錄:
- 關於unused 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於unused 在 Minsley Facebook 的最佳解答
- 關於unused 在 Facebook 的最佳貼文
- 關於unused 在 translation Youtube 的最讚貼文
- 關於unused 在 translation Youtube 的最佳貼文
- 關於unused 在 translation Youtube 的精選貼文
- 關於unused 在 消除編譯警告unused parameter 的評價
- 關於unused 在 eslint-plugin-react/no-unused-state.md at master - GitHub 的評價
- 關於unused 在 How do you disable the unused variable warnings coming out ... 的評價
unused 在 Minsley Facebook 的最佳解答
今天就是要懒懒的💚
.
.
Go green💚
Innisfree has been doing some campaigns to recycle plastics and even unused makeup products. Not only that we have to save our lovely earth, we also have to save our skin from the sun! 🌞
Skin brightening and tone up are very important in these days,even though we are staying at home.🤎
📸: @_janeleee
@stylekorean_global @innisfreeofficial @innisfree.instalog
#stylekorean #stylekorean_global #innisfree #trymereviewme #trymereviewme_innisfree
unused 在 Facebook 的最佳貼文
[🔴EN] [🟠ES] [🟡DE] [🟢JA]
[🔴EN]
Unused pictuares
Photo_Sayo Nagase @say0ngs
Styling_Sumire Hayakawa @sumire_hayakawa_stylist
Hair & Make-up_Megumi Kuji @megumikuji_luckhair
Model_Daoko
#GIRLHOUYHNHNM
#got2b #got2bカラー
🔵Find the translation for each picture in their respective descriptions❗
[🟠ES]
Fotos inéditas
Foto_Sayo Nagase @say0ngs
Estilizado_Sumire Hayakawa @sumire_hayakawa_stylist
Cabello y maquillaje_Megumi Kuji @megumikuji_luckhair
Modelo_Daoko
#GIRLHOUYHNHNM
#got2b #got2bカラー
🔵¡Encuentra la traducción de cada imágen en su respectiva descripción❗
[🟡DE]
Nicht verwendete Fotos.
Foto_Sayo Nagase @say0ngs
Styling_Sumire Hayakawa @sumire_hayakawa_stylist
Haare & Make-up_Megumi Kuji @megumikuji_luckhair
Modell_Daoko
#GIRLHOUYHNHNM
#got2b #got2bカラー
🔵Finde die Übersetzung jedes Bildes in der jeweiligen Bildbeschreibung❗
[🟢JA]
おふしょっと
Photo_Sayo Nagase @say0ngs
Styling_Sumire Hayakawa @sumire_hayakawa_stylist
Hair & Make-up_Megumi Kuji @megumikuji_luckhair
Model_Daoko
#GIRLHOUYHNHNM
#got2b #got2bカラー
🔵それぞれの写真に訳したキャプションがあります❗
@Daoko_official on Instagram
unused 在 translation Youtube 的最讚貼文
#'90年にセガ第2AM研究開発部が開発、セガが稼働させた、AC用3DSTG作品。ゲームデザインは鈴木裕氏が担当。
難易度選択後、F-14風の機体・A8M5 MkII "ZEEK"に搭乗、バルカンとミサイルを駆使し、制限時間内に規定数の敵機を撃墜するとステージクリア。
BGMはHiro師匠と後輩の高木氏が共同作曲、回転型筐体R-360版BGMを光吉氏が作曲。
作曲:川口博史氏、高木保浩氏、光吉猛修氏(R-360版)
Manufacturer: 1990.05 SEGA /Sega AM2
System: SEGA Y BORAD
Hardware: YM2151, Sega PCM
composer : hirodhi kawaguchi,Yasuhiro Takagi,Takenobu Mitsuyoshi
--------------------------------------------------
00:00 01.Coin / コイン投入
00:02 02.Opening / オープニング
00:47 03.BGM A / ステージBGM1
03:01 04.BGM B / ステージBGM2
03:36 05.谷間の空中戦 BGM
06:56 06.BGM C / ステージBGM3
09:09 07.BGM D / ステージBGM4
10:04 08.地上攻撃 BGM
12:16 09.Last Mission / 最終ステージBGM
15:08 10.Continue / コンティニュー
15:38 11.Landing / 空母着艦
16:29 12.Congratulations / ゲームクリア
18:33 13.Phrase / Unused / ゲームクリア *残り時間100秒以上
19:03 14.Name Entry / ネームエントリー
21:59 15.Fanfare
22:04 16.Fanfare (Not Use) / 未使用
22:09 17.Earth Frame G / ステージBGM * R-360版追加曲
--------------------------------------------------

unused 在 translation Youtube 的最佳貼文
#'86年にアトラスが開発、イマジニアより発売された、FDS用縦スクロールシューティングアクションRPGであり、イマジニアのFCソフト参入第1作目。
WAVE JACKシリーズ(メディアミックス)の第1作でもある。
宇宙空間は縦スクロールSTG、惑星に下りてからは縦スクロールアクションSTGとなる。マニュアルと短編小説、設定資料、古代文字の発音表、カセットテープが同梱されておりそれらを参考に進めていく。テープではボイスドラマと荻野目洋子さんによる主題歌が収録。
BGMは増子氏が作曲、増子氏がアトラスに移籍してからの初の作品となる。
作曲:増子司氏
Manufacturer: 1986.11.06 Imagineer / Atlus
Hardware: RP2A03,RP2C33
computer: family computer
Composer: tsukasa masuko
----------------------------------------------------
00:00 01.Prologue (タイトル)
04:17 02.Shooting BGM (シューティングステージ)
07:54 03.Esdaal, the 5th Satellite (エスダール/第5衛星エスダール)
09:17 04.Plantus, the 4th Satellite (第4衛星プランタス)
10:15 05.Rekshe, the 3rd Satellite (第3衛星レイクシー)
11:19 06.Daal, the 2nd Satellite (第2衛星ダール)
13:10 07.Mylus, the 1st Satellite (第1衛星マイラス)
15:08 08.Planet Hope (ホープ星/ラストステージ)
17:21 09.Hidden Passage
17:26 10.Bonus
17:31 11.Unused Tune (未使用)
----------------------------------------------------

unused 在 translation Youtube 的精選貼文
#任天堂が発売した、GB用RPG作「ポケットモンスター 赤・緑」('96年)からのGBA移植版。
ゲームフリーク、クリーチャーズが開発を行った。
ルビー・サファイアのシステムをベースとし、原作のストーリーを踏襲しつつアレンジや追加要素がある。
主な変更点としては、とくせいやダブルバトルの導入等の基本システムがRS準拠、主人公を男女から選択可、新規トレーナーの追加、一部トレーナーの名称が変更、ナナシマがマップに追加、ヘルプ機能が随時起動可、初心者救済のおしえテレビが追加、いくつかのイベントが修正、出現ポケモンの一部変更、ポケモンの出現場所が一部変更、わざおしえが復活、トレーナーカードにシール要素が追加、ワイヤレスアダプタによる無線通信が可等が挙げられる。
BGMはゲームフリークの一之瀬氏、増田氏、青木氏による共同作・編曲。サンダー・ファイヤー・フリーザーとミュウツーに新規曲(野生ポケモン戦のアレンジ)が設定されている。
効果音:一之瀬剛氏
作曲:一之瀬剛氏、増田順一氏、青木森一氏
Year: 2004.01.29(J),2004.09.09(U)(CAN),2004.09.23(AU)(NZL)
Manufacturer: Nintendo / Creatures,Game Freak
System: 8bit sound chip.pAPU
hardware: game boy advance
Sound Effect: Go Ichinose
Composer & Arranger: Go Ichinose, Junichi Masuda,Morikazu Aoki
----------------------------------------------------------------------------------------------------------
00:00 01.GameFreakロゴ *FRLG追加曲
00:09 02.オープニングデモ
00:21 03.~オープニング~
01:59 04.ゲーム説明 (Part 1) *FRLG追加曲 あたらしくはじめる選択後BGM
02:14 05.ゲーム説明 (Part 2) *FRLG追加曲
02:49 06.ゲーム説明 (Part 3) *FRLG追加曲
02:52 07.ポケモンの世界へようこそ *マサキのもとへ-ハナダより
03:44 08.マサラタウンのテーマ
05:23 09.オーキド博士 / オーキド博士と初めて会話する時の曲
06:11 10.オーキド研究所
06:56 11.ポケモン獲得
06:59 12.ライバルあらわる / ライバル戦闘前
07:47 13.トキワへの道-マサラより / 1ばんどうろ
08:47 14.戦い / VS野生ポケモン
10:16 15.勝利(VS野生ポケモン / 野生ポケモンに勝利
10:57 16.ニビシティのテーマ / トキワシティ / ニビシティ / ヤマブキシティ
13:11 17.ポケモンセンター
14:29 18.ポケモン回復
14:32 19.トキワの森
18:15 20.道案内 / ニビシティの道案内イベント
18:49 21.トレーナーあらわる /女の子編 ミニスカートなど戦闘前BGM
19:07 22.戦い / VSトレーナー 一般トレーナー戦
22:18 23.勝利 / VSトレーナー トレーナーに勝利
22:59 24.おつきみ山のどうくつ
26:16 25.ハナダへの道-おつきみ山より / 4ばんどうろ
27:34 26.セキチクシティのテーマ *ハナダシティのテーマ
28:52 27.ポケモンジム / ポケモンジム内部
30:10 28.プリンの歌 / ニビシティ・ポケモンセンターのプリン会話
30:18 29.クチバシティのテーマ
31:45 30.サントアンヌ号
34:11 31.セキチクへの道-シオンタウンより / 11~15ばんどうろ *シオンへの道-クチバより
35:29 32.ポケモンの笛 *アイテム「ポケモンのふえ」使用時
35:38 33.トレーナーあらわる(男の子編 / たんぱんこぞう他戦闘前BGM
35:59 34.戦い(VSジムリーダー) / ジムリーダー戦
38:01 35.勝利 (VSジムリーダー) / ジムリーダーに勝利
39:41 36.サイクリング / アイテム「じてんしゃ」使用
41:01 37.シオンタウンのテーマ
43:50 38.ポケモンタワー
45:59 39.タマムシシティのテーマ
47:26 40.カジノ / タマムシゲームコーナー
49:04 41.トレーナーあらわる(悪いヤツ編 / ロケットだんいん他戦闘前BGM
49:25 42.ロケット団アジト / タマムシゲームコーナー地下
52:03 43.シルフカンパニー / シルフカンパニー内部
54:07 44.海 / ひでんわざ「なみのり」使用中
55:20 45.グレンタウンのテーマ
56:39 46.ポケモン屋敷 / ポケモンやしき
58:47 47.進化 / ポケモン進化デモ / 通信交換 / サファリゾーン内
59:30 48.最後の道 / 23ばんどうろ / セキエイこうげん
01:00:42 49.ラストバトル(VSライバル) / チャンピオン戦
01:03:07 50.殿堂入り / でんどういりポケモン紹介デモ
01:04:14 51.~エンディング~ / エンディングスタッフロール
01:08:26 52.ファンファーレ ポケモン入手 *FRLG追加曲 イベントでポケモン入手時の効果音
01:08:30 53.ファンファーレ どうぐゲット1 *FRLG追加曲 普通の道具入手効果音
01:08:32 54.教えテレビメニュー *FRLG追加曲 アイテム「おしえテレビ」使用
01:08:46 55.ファンファーレ バッジゲット *FRLG追加曲 ジムバッジ入手効果音
01:08:52 56.ファンファーレ 進化おめでとう *FRLG追加曲 ポケモン進化後効果音
01:08:57 57.対戦の緊張! *FRLG追加曲
01:09:18 58.ファンファーレ 当たり! *FRLG追加曲 スロットゲームで「R」か「7」がそろった時の効果音
01:09:22 59.ファンファーレ 大当たり! *FRLG追加曲 スロットゲームで「R」か「7」がそろった時の効果音
01:09:28 60.ファンファーレ ポケモンゲット *FRLG追加曲 ポケモンゲット効果音
01:09:32 61.ファンファーレ オーキド評価 *FRLG追加曲 オーキド博士の図鑑評価効果音
01:09:36 62.ポケモンプリント *FRLG追加曲 ゲームコーナーのプリンター使用
01:09:39 63.わざ忘れ *FRLG追加曲 わざわすれ効果音
01:09:42 64.戦い(VS伝説のポケモン) *FRLG追加曲 伝説のポケモン戦BGM
01:11:10 65.ポケモンネットワークセンター *FRLG追加曲 1のしまPNCのBGM
01:12:28 66.ナナシマ4・5の島 *FRLG追加曲 4のしま/5のしまBGM
01:14:20 67.ミニポケモンでジャンプ *FRLG追加曲 通信対戦用ミニゲーム
01:16:03 68.ドードリオのきのみどり *FRLG追加曲 通信対戦用ミニゲーム
01:17:39 69.残念 *FRLG追加曲 通信対戦用ミニゲーム
01:17:43 70.ナナシマ *FRLG追加曲 4~7のしまの道路BGM 金・銀 42ばんどうろのアレンジ
01:19:04 71.ナナシマ6・7の島 *FRLG追加曲 6のしま/7のしまBGM 金・銀 キキョウシティのアレンジ
01:20:32 72.ユニオンルーム *FRLG追加曲 ポケモンセンター2階、通信交換のための部屋BGM
01:22:17 73.ふしぎなおくりもの *FRLG追加曲 メニュー「ふしぎなおくりもの」BGM
01:23:02 74.戦い(VSミュウツー) *FRLG追加曲 ミュウツー戦BGM
01:24:29 75.デオキシス登場 *FRLG追加曲 デオキシス戦闘前デモBGM
01:25:11 76.戦い(VSデオキシス) *FRLG追加曲 デオキシス戦BGM
01:27:49 77.エピローグ *FRLG追加曲 エンディング後
01:29:48 78.Fanfare Item Get 2
01:29:51 79.Pokemon Institute (RS)
01:31:18 80.Battle (VS Trainer) (RS)
01:34:17 81.Battle (VS Gym Leader) (RS)
01:36:49 82.Fanfare Berry Get (RS)
01:36:52 83.Fanfare TM & HM Get (RS)
01:36:57 84.Rival Appears (No Intro)
01:37:43 85.Victory (VS Wild Pokemon) (No Intro)
01:38:22 86.Pokemon Recovery (Unused)
01:38:25 87.SE
------------------------------------------------------------------------------------------------------

unused 在 eslint-plugin-react/no-unused-state.md at master - GitHub 的推薦與評價
Prevent definitions of unused state (react/no-unused-state). Warns you if you have defined a property on the state, but it is not being used anywhere. ... <看更多>
unused 在 消除編譯警告unused parameter 的推薦與評價
本篇介紹GCC 移除unused parameter 編譯警告的方法,gcc 編譯時開啟-Wall 會出現很多警告,如果要解決unused parameter 這種的警告解決方式有三種, ... ... <看更多>