📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有6部Youtube影片,追蹤數超過9萬的網紅Smart Travel,也在其Youtube影片中提到,成為這個頻道的會員並獲得獎勵: https://www.youtube.com/channel/UCIuNPxqDGG08p3EqCwY0XIg/join #WEGOJapaneseStore #日本潮店 #日本旅行 #osakamustbuy #日本wego必買 #大阪必買 #大阪心齋橋 #we...
「in short supply」的推薦目錄:
- 關於in short supply 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於in short supply 在 SABAH, Malaysian Borneo Facebook 的精選貼文
- 關於in short supply 在 Milton Goh Blog and Sermon Notes Facebook 的最佳貼文
- 關於in short supply 在 Smart Travel Youtube 的最讚貼文
- 關於in short supply 在 I’m宇晴 Youtube 的最佳解答
- 關於in short supply 在 CarDebuts Youtube 的最佳貼文
- 關於in short supply 在 New cars in short supply - YouTube 的評價
in short supply 在 SABAH, Malaysian Borneo Facebook 的精選貼文
Tea time with an ocean view, anyone? ☕
Being one of the best tourism destinations in Malaysia, Sabah is not in short supply of white beaches, nature adventures and picturesque landscapes. Anything your travelling desires, from climbing Mount Kinabalu to island hopping and culinary experience, you would find it all here.
📸 IG: @by__fia
📍 @suteraharbourofficial, Kota Kinabalu
#sabah #borneo #malaysia #tourism #photooftheday #nature #fun #photography #beautiful #enchantingsabah #travellater #traveltomorrow #resort
in short supply 在 Milton Goh Blog and Sermon Notes Facebook 的最佳貼文
Be Conscious of The Supply
“For if by the trespass of the one, death reigned through the one; so much more will those who receive the abundance of grace and of the gift of righteousness reign in life through the one, Jesus Christ.” (Romans 5:17 WEB)
Is death reigning, or is life reigning, in your life?
The strategy to enjoy a blessed life is so simple, but many of us just don’t do it.
If you are constantly worried, fearful, and pessimistic about your future, it simply means that you have not been consistently receiving the Gospel. One way to describe the Gospel would be “the abundance of grace and of the gift of righteousness”.
Instead, the world’s words and pictures based on wrong beliefs have filled your heart, producing forms of death.
We need to hear about the abundance of grace and the gift of righteousness because the enemy wants us to feel lacking and vulnerable. One way he advances his goal is by broadcasting bad news designed to instill fear and worry.
“in which you once walked according to the course of this world, according to the prince of the power of the air, the spirit who now works in the children of disobedience;” (Ephesians 2:2 WEB)
The apostle Paul called the devil “the prince of the power of the air”. This means that he has power over the airwaves. Besides weather manipulation, the devil also attacks by releasing words (essentially frequencies of vibrations in the air). We know that he is a liar, and he can be quite convincing at times.
Are you more conscious of the many demands upon you, or are you more conscious of the supply that is freely available to you by faith?
God’s grace is His unmerited favor towards you, when He gives you good things that you did not deserve by your own works.
If they are gifts for you, then who paid the cost? Jesus paid not with corrupt, perishable things like money. He paid with His own divine blood (the life of the flesh is in the blood).
He bled and literally gave His life—the life of God, for you.
I once shared in a short video teaching that the Hebrew letters for the word “Amen” are aleph (God/ sacrificial animal), mem (water flowing down like a waterfall), and nun (offspring/child).
They form a picture of blessings pouring down upon you like a waterfall, from Jesus the sacrificial Lamb at the cross, to you who are now God’s beloved child.
Every time you say “Amen”, picture the blood-bought blessings flowing from Jesus at the cross, to you. It is like making a withdrawal from your heavenly bank account.
The Lord is your Shepherd. He laid down His life for you, and you will not lack in any way because He is your inexhaustible supply!
Are you under spiritual attack from the enemy? This is not an area that you have to fear or be ignorant about. The Bible teaches us about the powerful spiritual weapons we have in Christ.
If you have a long-time bondage or addiction, you can be set free when you know the truth of how all this works. I compiled the book “Silencing the Serpent” for these reasons and more. Get it here: https://bit.ly/silence-the-serpent-now
in short supply 在 Smart Travel Youtube 的最讚貼文
成為這個頻道的會員並獲得獎勵:
https://www.youtube.com/channel/UCIuNPxqDGG08p3EqCwY0XIg/join
#WEGOJapaneseStore #日本潮店 #日本旅行 #osakamustbuy #日本wego必買 #大阪必買 #大阪心齋橋 #wego分店 #日本潮牌
Hello大家好, 我叫阿Tsar Hello, everyone.
今日帶大家去到大阪心齋橋一間潮店shopping Today I will take you to shopping in Shinsaibashi, Osaka
去日本旅行對這個品牌一點都不陌生WEGO Japanese Store U will find this brand WEGO familiar in Japan
如果講日本街頭潮流文化, 大家都會想起Supreme If u talk about Japanese street fashion, everyone will think of Supreme
Supreme在1994年出於倫敦的設計師James Jebbia在紐約SOHO創立出來的 Supreme was founded in 1994 in SOHO of New York by British designer James Jebbia
Supreme買得那麼貴的原因, 就是因為本身設計師好有性格, 設計好多限量版的時裝 The reason Supreme bought so expensive is because the designer has designed a lot of limited-edition fashions.
懂得利用Hunger Marketing飢餓行銷, 即是好多限量版, He made use of Hunger Marketing which has a lot of limited editions,
製造供不應求的.的「假象」, Manufacturing in short supply for making a scence of shortage
加上又講得跟名牌好像Louis Vuitton還有好多名牌玩crossover Plus crossover with the famous brands like Louis Vuitton n many other famous brands
所以買到普通一件T恤都要過千元HKD, So that a simple T-shirt is selling more than a thousand HKD,
而我今日介紹的WEGO Japanese Store, 它是日本一個好出色的街頭文化品牌 The WEGO Japanese Store that I introduce today, it is a famous street culture brand in Japan
但是它的價錢就便宜好多好多,價格非常親民,而且男女裝都有 But its price is a lot cheaper n affordable for men and women.
在日本的年青人由15歲至到25歲, 最少擁有一件WEGO Young people in Japan from 15 to 25 years old, own at least one WEGO
WEGO比 Supreme更平價, 但是比起平價的UNIQLO色彩款式更豐富 WEGO is more affordable than Supreme, but more details n colorful than the cheap UNIQLO
你可能認為WEGO, 只會適合年青人啦?! You might think that WEGO is only suitable for young people ?!
我不同意這個講法! 因為年齡只是一個數字 I disagree with this! Because age is just a number
而穿衣只會顯示你當時的心情, 好像現在的社會氣氛 Dressing will only show your mood at that moment, specially for the current social atmosphere
我認為, 大家應該可以用色彩對你的生命注入一點繽紛元素 I think that everyone should be able to erich your life with colors
片尾我會介紹幾句日文的潮語給大家, 如果你對這方面有興趣 At the end of the video, I will introduce a few Japanese slangs to u. If u are interested in this,
記得看到片尾, 看完記得给我表情符號以示支持 Remember to watch till the end, also give me an emoji to show support
事不宜遲, 快點看看今日的十大必買, are you ready? Let's move on to take a look at today's top 10 best-buy, are you ready?
第一必買, 如果大家以為腰包是的士司機、小販的專利 1st best buy is belt bag. ........
今日的分享大致上是這樣, 還記得我跟大家有個約會嗎 This is about what I am sharing for today. Remember we have a date?
我應承過大家寫一份5日4夜大阪行程規劃, I promise everyone to write a 5-nites 4 days Osaka itinerary plan,
這個行程規劃將會在我五月尾放完大假之前寫好給大家 This itinerary plan will be written for everyone before the end of May.
希望可以令到大家planing, 怎樣去大阪可以玩得輕鬆easy I hope that everyone can plan easily n have fun going to Osaka next time
還可以分享給你們的團友, 不用自己煩 U can also share it with your friends travel together, save a lot of trouble by watching my videos!
當中會有好多資訊分享, 我的大阪播放清單超過100條影片 There will be a lot of information to share, my Osaka playlist has more than 100 videos
將會放在google map的行程規劃, 所以大家一定會看得清楚 It will be placed on the google map itinerary plan, so everyone will see it clearly
另一個同大家的約會, 就會在我五月放完大假之前開live
已經收到好多網友的提議講鬼故, 之前我會通知大家何時做直播
不會留底, 所以不會嚇怕其他不想聽鬼故的網友
如果大家喜歡我的介紹, 記得幫我分享訂閱和like If you like my sharing today, please remember to CLS
我的下一條片再傾過日本的其他話題, My next video will cover other topics in Japan,
日文晚安 Oyasumi nasai Good nite in Japanese is "Oyasumi nasai!"
我們下次再傾過, 88, Oyasumi nasai With that said untill next time, 88.
請用片右下角調4K睇片。
みなさん、こんにちは、Ah Tsarです。
今日は大阪心斎橋のタイドショップで買い物に連れて行きます
日本への旅行は、このブランドWEGO Japanese Storeに慣れています
日本のストリートカルチャーについて言えば、誰もが最高の
Supremeは1994年にロンドンのSOHOのデザイナーJames Jebbiaによってニューヨークで設立されました。
Supremeが非常に高価に購入した理由は、デザイナーが個性を持ち、限定版のファッションを数多くデザインしたためです。
多くの限定版であるハンガーマーケティングのためのハンガーマーケティングの使用方法を知っている、
供給不足での製造。 "想像力"、
さらに、ルイ・ヴィトンのような有名ブランドと話をしなければなりません。クロスオーバーをプレイしている有名ブランドがたくさんあります。
通常のTシャツを1000香港ドル以上購入する必要があります。
今日紹介したWEGOジャパニーズストアは、日本のストリートカルチャーブランドです
しかし、その価格ははるかに安く、価格は人々に非常に近く、そして男性と女性の両方が持っています
15歳から25歳までの日本の若者で、少なくとも1つのWEGOを所有している
WEGOはSupremeよりも手頃な価格ですが、安いUNIQLOカラースタイルよりも豊富です
WEGOは若者だけに適していると思いますか?!
私はこの声明に同意しません!年齢は単なる数字なので
そして、ドレッシングは、あたかも現在の社会的な雰囲気のように、その時の気分だけを表示します
誰もが色であなたの人生に小さなカラフルな要素を注入できるはずだと思います
映画の最後に、この側面に興味があれば、日本の流行語をいくつか紹介します
映画の最後を見ることを忘れないでください、そしてそれを読んだ後、私にサポートを示すために絵文字を与えることを忘れないでください
さらに騒ぎ立てずに、今日の必需品トップ10を見てみましょう。準備はいいですか。
誰もがウエストバッグはタクシーの運転手や行商人の特許だと思っているなら、最初のものを買う必要があります
それであなたはとても間違っています、グッチ、エルメス、ドワールもベルトバッグなどの製品を製造しています
WEGOにはさまざまなスタイルがあります
顔に口紅・水・お財布などが置けて、軽くて便利................
in short supply 在 I’m宇晴 Youtube 的最佳解答
Hi!! 最近好愛微波浪捲髮,尤其是我現在頭髮要長不短的很適合用這樣的髮型🌹裡面有許多小技巧大家可以練習練習,捲頭髮其實都是練出來的!多做幾次就可以捲出漂亮的弧度,有問題在下面留言告訴我~
補充)) 電棒捲用26mm
#howistylemyhair #wavyhair #如何整理我的頭髮 #電棒整理
🍒Products I used.🍒
•AVEDA Wooden Paddle Brush 梳子
https://rstyle.me/+NKm10zjqIQQ9K14jrX41PA
•AG hair 抗熱噴霧
https://rstyle.me/+PQfnn-C1arvR6JcFjMddmA
•Salon sense 300 (26mm)日本購入
•GFD Gold Professional 1” Styler 離子夾
(2”同款)https://rstyle.me/+rvWpZLuDjgBbG46huX0U6w
(1”不同款)https://rstyle.me/+8d-WXRw60bH26XaVfLVlrg
•NUXE huile prodigieuse 髮油
•TANGLE TEEZER Compact Styler 梳子
https://rstyle.me/+9ERfUbmlckDVum_1geRyxQ
#ootd
Z Supply (s)黑色一字領:http://slooks.top/2RVD
ASTRID AND MIYU Basic Large Beaded Choker in Gold 項鍊
https://rstyle.me/+ktQRo1dqv1VNWJtaXSD4zA
thanks for watching :)
Please SUBSCRIBE&Give It a THUMBS-UP! xoxo
https://goo.gl/d0kBP2
🌹FB-施宇晴
https://facebook.com/shihbeibei
🌹Instagram-beibeibei0106
http://www.instagram.com/beibei_shih
💌Mail:arielshih16@gmail.com
in short supply 在 CarDebuts Youtube 的最佳貼文
ชมขั้นตอนการผลิต โดยละเอียด All-New 2019 BMW 3-Series ที่โรงงานในเมือง San Luis Potosi เม็กซิโก
San Luis Potosi/Munich. High-level representatives of the Mexican government and the BMW Group officially opened the company’s new automotive plant in San Luis Potosi in Mexico today.
Oliver Zipse, member of the Board of Management of BMW AG responsible for Production, stated during the ceremony: “The new plant in San Luis Potosi is an important pillar of the BMW Group’s global production strategy. We aim to achieve a balance in our production and sales in the different world regions. We want to strengthen our footprint in important and growing markets. Plant San Luis Potosi will significantly boost our regional production flexibility in the Americas. From here, we are delivering our locally produced BMW 3 Series Sedan to customers worldwide.”
The company has invested more than one billion US dollars in the new production location. The plant, which already employs 2,500 people, will have a capacity of up to 175,000 units per year once the ramp-up phase is fully completed.
San Luis Potosi will build the BMW brand’s most successful model series: the BMW 3 Series Sedan. In the company’s more than 100-year history, this iconic car has come to represent the heart of the brand, setting the standard for dynamic performance, efficiency and design.
The ceremony in San Luis Potosi was attended by guests including Dr. Alfonso Romo Garza, Head of the Office of the Presidency of the Mexican Republic; Dr Juan Manuel Carreras López, governor of the state of San Luis Potosi; Oliver Zipse, member of the Board of Management of BMW AG responsible for Production; Milagros Caiña-Andree, member of the Board of Management of BMW AG responsible for Human Resources and Labour Relations, and Dr Andreas Wendt, member of the Board of Management of BMW AG responsible for Purchasing and Supplier Network.
Head of Human Resources Milagros Caiña-Andree highlighted the BMW Group’s strong commitment to vocational education: “Our highly-trained employees form a strong foundation for our new BMW Group Plant San Luis Potosi and help us meet high quality standards for our premium products. Our dual vocational training programme is already in its fourth generation.”
At an innovative new training centre on the plant grounds, all new staff and apprentices are trained in the BMW Group’s latest production processes and technologies, based on the dual vocational training model. The centre is not just focused on expanding employees’ and apprentices’ technical skills, but also boosting motivation, enthusiasm and team spirit.
The plant is working with four technical institutes in this area and has already trained 250 apprentices in technical occupations.
Dr Andreas Wendt, member of the Board of Management of BMW AG responsible for Purchasing and Supplier Network: “We have a strong supplier base we can build on in Mexico, having sourced high-quality, technologically sophisticated and innovative products from here for more than ten years. Every BMW Group vehicle today already contains at least one part from one of our 220 Mexican suppliers. Our new plant will benefit from short supply routes and the high level of flexibility this gives our supply chain.”
The BMW Group has operated its own local purchasing office in Mexico since 2008. In 2017, the office relocated from Mexico City to San Luis Potosi, where it now employs 105 people. The BMW Group’s purchasing volume in Mexico reached USD 2.5 billion last year.
in short supply 在 New cars in short supply - YouTube 的推薦與評價
... <看更多>