📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有10部Youtube影片,追蹤數超過24萬的網紅I'm Jonas,也在其Youtube影片中提到,台灣不需要核能和火力發電?3個使用更多再生能源的方法! | 3 Ways for Taiwan to get more renewable energy! 這部影片僅以個人看法說明,主要希望以輕鬆的方式帶大家初步了解再生能源,並透過真實案例及台電數據,提供以自身角度及經驗介紹給大眾。因電力系統非常...
「case scenario」的推薦目錄:
- 關於case scenario 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於case scenario 在 Keyman Facebook 的最佳貼文
- 關於case scenario 在 Dr. Kayla Teh Facebook 的最讚貼文
- 關於case scenario 在 I'm Jonas Youtube 的最佳貼文
- 關於case scenario 在 Appleが大好きなんだよ Youtube 的最佳貼文
- 關於case scenario 在 Dr. Amalina Youtube 的最佳解答
- 關於case scenario 在 Worst Case Scenario - YouTube 的評價
case scenario 在 Keyman Facebook 的最佳貼文
名宿奧雲話:
連加特嗰球波好靚
唯一美中不足嘅就係
佢對住前度入波唔慶祝
球波咁靚都唔慶祝嘥料囉
如果你真係咁唔想入嘅
你可以將個波交俾隊友
你就唔好拉弓唔好起腳
而我終於
明白奧雲
係乜嘢人…
"The finish is absolutely sublime," Owen told Premier League Productions. "The only thing that is poor about the whole scenario is that he doesn’t celebrate.
"I can’t believe players don’t celebrate when they score a goal against their old club, he was only there two minutes
"If he didn’t want to score, if he’s not that happy don’t pull the trigger, pass the ball, if that’s the case.
"It’s the only thing that lets him down there, because everything else is absolutely spectacular."
case scenario 在 Dr. Kayla Teh Facebook 的最讚貼文
Fiber-reinforced Bridge…do you know what that is?🤔
When you lost a tooth or teeth, you have a few options to replace it: denture, bridge, implant, braces or more.
She first came in with loose denture replacing her two front teeth. Denture is a good replacement option for missing teeth but with time, it tend to become loosen due to bone resorption (“bone thinning”). Loose denture can be troublesome as it falls out easily (no one wants their teeth falling out during a presentation!😱) and food often get stuck underneath it.
If you ask me, implant is the best option to replace this patient’s missing teeth. However, implants (and not forgetting bone graft) placement can be costly and she is not financially ready for it. Having the option for a new denture or a fiber-reinforced bridge, she decided to choose the latter whilst preparing for her implant budget.
The challenge in this case is the total buildup of the tooth with composite, estimating it’s size/shape/shade and not forgetting occlusion. This is a non-prep case as the patient is biting rather incisally on the anteriors while having good posterior occlusion(thus made her a good candidate for this long span FRB case).
Most of it has to be done chair-side, thus a lot of clinical time has been spent. Note that the 11,21 are shortened as well although I would LOVE to give her a perfect smile arch, due to concerns of her anterior guidance.
Patient was super happy she has semi-permanent teeth inside her mouth and don’t have to worry about her denture falling out anymore. (We both still look forward to the day implants can be placed tho!🙈)
Case selection is important in FRB treatment. It is not for patients who want an easy way out, but for patients who clearly understand ALL the pros and cons of their treatment options and are willing to accept the worst-case scenario.
Okay that’s all, I know I talk a lot but I just wanted to share some of the stuff I’ve learned through this case. 😆 Have a great day y’all!
case scenario 在 I'm Jonas Youtube 的最佳貼文
台灣不需要核能和火力發電?3個使用更多再生能源的方法! | 3 Ways for Taiwan to get more renewable energy!
這部影片僅以個人看法說明,主要希望以輕鬆的方式帶大家初步了解再生能源,並透過真實案例及台電數據,提供以自身角度及經驗介紹給大眾。因電力系統非常複雜需具專業性,相關主題之後會更深入了解,不具任何立場喔。
Thank you so much for watching todays video! All my data is based on the demand and production on 27th May, which was a hot and sunny day. This video is meant to be entertainment and an introduction to renewable energy inspired by a real case scenario. Power systems are very complex, so to make any suggestion for the future, a much deeper analysis is needed.
References:
Electricity demand of Taiwan (27th May):
https://www.taipower.com.tw/en/page.aspx?mid=4484
Solar PV output in Taiwan (27th May):
https://www.taipower.com.tw/en/page.aspx?mid=4484&cid=2832&cchk=30760122-6d57-43cf-bcb8-0caba69e75a7
*PV output for 20GW and 40GW is also estimated based on this generation curve
20% Renewable goal by 2025:
https://www.taiwannews.com.tw/en/news/3880997
Coal, Nuclear, Natural Gas Capacity in Taiwan:
https://www.taipower.com.tw/en/page.aspx?mid=4484&cid=2834&cchk=20432baa-1f39-4018-aed8-7b33b02f942e
Hydro, wind, diesel and oil estimate based on this:
https://www.taipower.com.tw/en/page.aspx?mid=4484&cid=2832&cchk=30760122-6d57-43cf-bcb8-0caba69e75a7
Extra capacity in the grid:
https://www.taipower.com.tw/en/page.aspx?mid=4484&cid=2833&cchk=083f3aa1-77b0-43cf-9e4f-877a8a484c39
Comparison of flexibility between Coal and Natural Gas:
https://reader.elsevier.com/reader/sd/pii/S1364032117309206?token=7E89009F522E8EF9097CD7FC2DE4F49EF4A648E190B88781939C73A1197B48C989B0B4A4CCBE439C60AF2CDBF141668A&originRegion=us-east-1&originCreation=20210603055324
Comparison of emission for Coal and Natural Gas:
https://www.eia.gov/energyexplained/natural-gas/natural-gas-and-the-environment.php
Subscribe me:
http://bit.ly/1nTklXP
合作邀約請寫信到:
imjonastw@gmail.com
Thank you for watching! The more views/likes/shares the more time I can devote into making good videos. Thank you all!
Youtube: http://bit.ly/1nTklXP
Instagram: www.instagram.com/jonas.tjd
Contact: imjonastw@gmail.com
Facebook: https://www.facebook.com/iamjonast/
![post-title](https://i.ytimg.com/vi/ZjynPCT6I_E/hqdefault.jpg)
case scenario 在 Appleが大好きなんだよ Youtube 的最佳貼文
今日は月曜。ここ1週間分のAppleに関するニュースをアニメ「ミニオヤジ」を使ってまとめます。揉め事は置いといて、割とワクワクする内容が多かったです。
<引用させていただいたサイト>
9to5Mac
https://9to5mac.com/2020/08/21/kuo-iphone-12-5g-component-cost/
https://9to5mac.com/2020/08/23/apple-store-marina-bay-sands-singapore-opening-soon/
https://9to5mac.com/2020/08/22/apple-agrees-to-allow-wordpress-app-on-the-app-store-without-in-app-purchases-after-update/
https://9to5mac.com/2020/08/20/iphone-12-event-date-apple-posts-and-deletes-september-event-test-on-youtube/
記事内のTwitter
https://twitter.com/WeiRdCroissant/status/1296496965417656320
https://9to5mac.com/2020/08/19/apple-2-trillion-market-cap-2/
https://9to5mac.com/2020/08/17/iphone-12-images-dummy-units-cases/
Svetapple(iPhone12のコンセプト画像)オススメです。
https://svetapple.sk/novinky/iphone-12-with-5-4-inch-display-exclusive-renders-from-svetapple-sk/
Business
https://markets.businessinsider.com/news/stocks/apple-stock-price-could-surge-best-case-scenario-trillion-valuation-2020-8-1029524138#
MacRumors
https://www.macrumors.com/2020/08/21/apple-certified-refurbished-10-2-inch-ipad/
https://www.macrumors.com/2020/08/20/applecare-one-year-purchase-option-details/
https://www.macrumors.com/2020/08/20/apple-dominated-smart-watch-market-1h-2020/
https://www.macrumors.com/2020/08/20/vmware-fusion-12/
https://www.macrumors.com/2020/08/19/ipad-air-4-launch-march-2021/
Twitte
https://twitter.com/a_rumors1111/status/1258395063610007552
https://twitter.com/jon_prosser/status/1296449116353044480
<関連動画>
WatchとiPadは9月?iPhone 12は10月?にフォートナイトの乱!今週のApple 2020/8/17・ほぼ週刊のニュースと噂まとめ
https://youtu.be/Bq2MyW4QnWE
PASMOがいよいよ!新マップや新型iMac!今週のApple 2020/8/10・ほぼ週間 ニュースと噂まとめ
https://youtu.be/i8UGInA-ZG4
次期新型iPhone 12シリーズ用とされるケース全3サイズ入手!どんなサイズ感か既存機種と比較して遊んでみた・5.4インチ6.1インチ6.7インチケース
https://youtu.be/0hd6gCI5uAo
iPhone 12は10月/Face ID Mac/Watch Series6などAppleのニュースと噂まとめ・2020年7月後半
https://youtu.be/s6TamVX5V9A
Apple恐るべし!アニメ「ミニオヤジ」がニュース解説・4月5月6月にiPadとMacがバカ売れしていた!Appleの2020第3四半期業績発表
https://youtu.be/65DuA6Pq16k
撮影機材
・Panasonic Lumix GH5s
・Panasonic Lumix GH5
・Canon Power Shot G7X Mark II
・iPhone 11 Pro(Simフリー)
・iPhone 11(Simフリー)
・iPhone XS Max(Simフリー)
・iPhone X(Simフリー)
・iPadPro 11”(Simフリー)
・DJI OSMO Pocket
・Moment iPhone 外付けレンズ&専用ケース
動画編集
Final Cut Pro X
Adobe Illustrator(スライド)
Adobe Photoshop(スライド)
Adobe Character Animator(アニメーション)
※チャンネル全般で使っているものであって動画によって機材アプリは違います。
#Apple
#iMac2020
#ニュースと噂
![post-title](https://i.ytimg.com/vi/LD7c7xa-9Zo/hqdefault.jpg)
case scenario 在 Dr. Amalina Youtube 的最佳解答
Case study: 21 year-old woman presented to ED with abdominal pain.
The aim of this video is to guide medical students on how to do their OSCE examination. It is not a perfect scenario but can be used as a general guide.
Case simulation prepared by:
Dr Amalina Bakri (Doctor)
Dr Scarlet Nazarian (Patient)
Video edited by:
Omar Ghandour
![post-title](https://i.ytimg.com/vi/1VzfftqToD0/hqdefault.jpg)
case scenario 在 Worst Case Scenario - YouTube 的推薦與評價
Provided to YouTube by The Orchard Enterprises Worst Case Scenario · Joe Signature ℗ 2018 563 Music Released on: 2012-11-06 Auto-generated ... ... <看更多>