📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有3171部Youtube影片,追蹤數超過92萬的網紅ochikeron,也在其Youtube影片中提到,Karaage (also called Tatsutaage) is Japanese fried chicken. It is usually cooked for lunch, dinner, or bento. Also, it is the best party recipe favore...
「can i user」的推薦目錄:
- 關於can i user 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於can i user 在 貓的成長美股異想世界 Facebook 的最佳解答
- 關於can i user 在 Panda Loh Facebook 的最佳解答
- 關於can i user 在 ochikeron Youtube 的最佳貼文
- 關於can i user 在 ochikeron Youtube 的最佳貼文
- 關於can i user 在 ochikeron Youtube 的最佳貼文
- 關於can i user 在 How to detect Safari, Chrome, IE, Firefox and Opera browser? 的評價
- 關於can i user 在 Your browser is up to date - YouTube 的評價
- 關於can i user 在 Test Users - App Development - Documentation - Facebook 的評價
- 關於can i user 在 About GitHub Pages 的評價
- 關於can i user 在 Take control of your privacy online with the Off-Facebook ... 的評價
- 關於can i user 在 Is it "a user" or "an user" [duplicate] - English Stack Exchange 的評價
can i user 在 貓的成長美股異想世界 Facebook 的最佳解答
🌻
美國聯準會(Fed)在美東時間22日下午2時(台灣23日凌晨2時)宣布利率維持在趨近零的水準,但暗示升息可能會比預期來得快一些,同時也大幅下修今年的經濟展望。
https://udn.com/news/story/6811/5764746
🌻Adobe(ADBE)電話會議內容讀後感
ADBE前兩天發表財報了.
這次ADBE在財報後下跌, 主要是兩個原因(如下). 不過個人覺得是瑕不掩瑜:
1. 因為之前已經漲了不少(投資人期望太高)
2. 因為Digital Marketing這部分的業務受到季節性的影響, 所以表現不是很突出(沒有比預期高出很多)
a. net new Digital Media ARR (3% beat vs guide, vs 15% beat in 2Q21 vs 35% beat in 3Q20).
b. 有分析師在問(“Maybe just -- can we double-click on the seasonality commentary in the quarter? Because if we look at the beat versus guidance on net new digital media ARR, it looks, at the same time you had the weakest beat, but then the strongest guide in the last three years, which kind of speaks to and confirm some of those seasonality comments that you made.)
i. 高層對此的回答是, 主要是疫情後, 加上正值夏季, 大家的日子回復到正常&放假外出, 所以這部分的業務有受到影響(I think going into the quarter, we had expected that the consumer with a little bit more return to normalcy as what's happening in the environment.)
ii. 高層又說了一些話, 不過重點就是他不認為這是甚麼大事”So, net-net, I would say that the growth prospects for that particular business and the growth drivers remain intact. But again, very much in line. And this is what we feel good about the insights that we're getting on the business.”
iii. 也提到, Q4通常會是digital marketing業務的旺季(表現會不俗的意思)
另外, 覺得這次令我印象深刻的是, 當高層與分析師提到這些事情:
• 常在一些公司的電話會議中提到omnichannel這個字(疫情後, 更明顯了). 這次高層也有提到. ADBE可說是omnichannel概念股:
o “I mean, a big part of that is more and more companies are thirdly doing the multi-channel omnichannel, whatever they want to call it. And I think that's only going to continue to be a driver of our Digital Experience Solutions. Because today that stable stakes and so we just look at it and say whether you're shopping in-store over they are shopping online. You need a solution that treats you like a customer that we know of.”
• 網路上影片(video)的興起, 以及串流影音, 有提高了Adobe的營收天花板(用句分析師的術語, 就是TAM (total addressable market) expansion.
• 當使用者製作了越來越多的內容, 內容管理(content management)的能力就越顯重要, 內容上的流程管理(workflow)也越顯重要. Adobe的產品能夠幫內容製作者解決這樣的問題.
• 而Adobe各產品間的相容性, 標準化, 整合能力, 是它的競爭優勢之一:
o And one of the things we did really well is what we called our named user deployment and how, you know, when we have these enterprise licensing agreements, we offer enterprises the ability to download and distribute within the companies. And the more we do training and evangelism of the products, that leads to adoption. So, I would say there's an element of standardization, there's an element of more content.
而最近ADBE有個新聞, 引起了我的注意, 就是它即將在自己的平台上, 提供付款服務(payment service). 根據之前研究SHOP的經驗, 這有可能會對股價造成一定的漲幅:
On Sept. 15, Adobe announced that it will add payment services to its e-commerce platform this year to help merchants accept credit cards and other ways of paying. The move will deepen Adobe's rivalry with e-commerce firm Shopify (SHOP).
For the service, Adobe has partnered with PayPal (PYPL), which will process a variety of payment types, including credit and debit cards as well as PayPal's own payment and buy-now-pay-later offerings.
https://www.investors.com/news/technology/adbe-stock-adobe-beats-fiscal-q3-targets/
接下來該怎麼辦? 對於基本面良好的公司如ADBE, 我能說的就是buy the dip(逢低買進)了. 供參.
🌻The Facebook Files
一個星期前, WSJ上面有個關於FB的大篇幅調查報導. 有興趣的可以看看.
The Facebook Files
https://www.wsj.com/articles/the-facebook-files-11631713039
這篇文章挺長, 也沒有看到華爾街中文版本的完整翻譯, 不過可以看看這篇:
https://on.wsj.com/2ZmFimp
"《華爾街日報》的相關調查顯示,這家社交媒體巨頭心知肚明,其平台會傷害用戶,而且是以該公司常常完全了解的方式造成傷害。目前,全球近半數人口都是Facebook旗下平台的用戶。其中一些證據尤其令人不安:據《華爾街日報》報導,Facebook的內部研究顯示,在報告稱有過自殺念頭的青少年中當中,有13%的英國用戶和6%的美國用戶把這種念頭歸結於Instagram。"
另一篇相關新聞:
https://www.thenewslens.com/article/156683
"《華爾街日報》於13日揭露Facebook的XCheck系統,也就是內部系統中的VIP名單,數百萬名人、政治人物與記者等知名公眾人物都在特別的一份「白名單」之內。"
"這些「貴賓」在社群上發布的內容可以躲過一般的審查系統,即使發布明顯的不當內容,也不會立即被刪除。《衛報》報導,Facebook的獨立監督委員會表示,在閱讀該篇報導後,決定要審查XCheck系統,並要求Facebook對其進行報告與解釋。"
🌻我喜歡的Apple TV影集, "Ted Lasso", 是這次艾美獎的大贏家, 很多主要演員都得獎了.
很高興這兩年, 因為有這部戲的陪伴, 讓我撐過了疫情, 家人離世, 以及一些烏煙瘴氣的事情.
前幾天看演員的得獎影片, 一位娛樂記者問得獎的男配角(也是編劇之一)說, 你覺得這部片的核心思想是甚麼. 他說, be curious, not judgemental.
就像得獎的女演員在劇中一開始是很鴨霸很壞心的球隊主人, 但這樣做是因為被前夫傷透了心, 所以想要弄垮離婚後分到的財產(也是前夫的最愛--球隊); 外表看起來永遠陽光燦爛做啦啦隊的男主角, 在青少年時父親自殺, 造成了他心裡永遠的痛&障礙(讓他在球賽時, 會有突發恐懼症).
我們每個人其實都有很多面, 很多個故事. 尤其在社群, 大家都是萍水相逢, 對彼此的了解都是非常片面的; 而有時候在社群裡, 看到有人會因為只看到一個面向, 就去下斷語. 這其實是人之常情很難避免, 所以我們需要常用第二層思考去提醒自己. 社群裡需要更多的同理心.
“Be curious, not judgmental” – Walt Whitman(惠特曼)(美國詩人)
Picture來源:
https://www.apple.com/newsroom/2021/09/apples-global-hit-comedy-series-ted-lasso-sweeps-the-2021-primetime-emmy-awards-scoring-history-making-win-for-outstanding-comedy-series/
can i user 在 Panda Loh Facebook 的最佳解答
Yo guys! I have some things to share from @garniermalaysia with their commitments to achieve cleaner & greener beauty 😍
🍃 More recycled and recyclable packaging
🍃 More solidarity sourcing
🍃 Greener Sciences & formulas
🍃 More Renewable Energy
🍃 More actions to fight plastic pollution
I have the Garnier Green Beauty PR Kit with me and I love the message behind it! It is our responsibility to stay educated and aware of the impacts beauty products have on our planet earth! I am proud user of Garnier as they are taking a stronger approach in solidarity sourcing as well as more actions to fight plastic pollution. 🌱
As you can see in the photo, all Garnier products are certified Vegan, Halal & Cruelty Free. ✨
Furthermore, Garnier is using sustainable packaging helps reduce the effects of recent environmental issues! ♻ It is heart-warming to know that Garnier creates products that are made with the health of our bodies and the environment in mind.
Garnier as a brand has been committed to sustainability for years; producing more natural formulas, using sustainable and fair-trade ingredients, even being the first to bring certified organic products to the mass skincare market.
Garnier’s effort to not only care for us but as well as taking extra step to be more environmentally friendly. 🌍
Get yours now from the nearest Watsons stores or Watsons Online! 🛒🛒🛒
Sayangi Bumi, Go Green Beauty. Don’t forget to prepare a minimum of 3 recyclable items (size 500ml or less). Go to selected Watsons Malaysia outlets with Green Beauty Dropbox and GET rewarded when you recycle 🎁. Available until 27 Oct 2021 only, check it out from my stories now!
@garniermalaysia
@watsonsmy
#GarnierMalaysia #garniergreenbeauty #watsonsmalaysia #OneGreenStep
can i user 在 ochikeron Youtube 的最佳貼文
Karaage (also called Tatsutaage) is Japanese fried chicken. It is usually cooked for lunch, dinner, or bento. Also, it is the best party recipe favored by most people!
FYI: Dried soy meat I used.
https://amzn.to/3zBFQ4m
---------------------------------
Vegan Karaage (Soy Meat Fried Chicken) Recipe
Difficulty: Very Easy
Time: 40min (incl. marinating time)
Number of servings: 4
Ingredients:
100g (3.5oz.) dried soy meat blocks https://amzn.to/3zBFQ4m
* 2 tbsp. soy sauce
* 2 tbsp. sake
* 1 tbsp. grated ginger
* 1 clove grated garlic
* 1 tsp. sesame oil
2 tbsp. Katakuriko (potato starch)
deep frying oil
lemon wedges if preferred
Directions:
1. In a boiling water, cook dried soy meat blocks for 4 minutes. Or as directed on its package. Wash well (change water for a few times) to remove the bad smell, then drain well.
2. Mix the seasonings in a bowl and marinate the soy meat for about 30 minutes. Overnight is okay, longer makes them tasty.
3. Drain lightly (do not squeeze out the marinade liquid), coat with Katakuriko in a plastic bag.
4. Deep fry in oil at 180C (350F) until crisp golden brown.
5. Serve with lemon wedges if you like.
レシピ(日本語)
http://cooklabo.blogspot.com/
---------------------------------
Music by
YouTube Audio Library
Follow me on social media. If you have recreated any of my food, you can share some pictures #ochikeron. I am always happy to see them.
♥FOLLOW ME HERE♥
http://instagram.com/ochikeron/
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
♥My COOKBOOK available on Amazon Kindle♥
http://amzn.to/2EwR3ah
NO MORE hard copies... those who got one are lucky!
♥More Written Recipes are on my BLOG♥
http://createeathappy.blogspot.com/
♥My Recipe Posts in Japanese♥
http://cooklabo.blogspot.jp/
http://cookpad.com/ami
http://twitter.com/alohaforever
♥and of course PLEASE SUBSCRIBE♥
http://www.youtube.com/user/ochikeron?sub_confirmation=1
can i user 在 ochikeron Youtube 的最佳貼文
Here is the bubble solution recipe to make giant bubbles 😊
My darling made a bubble wand with two long chopsticks for cooking and knitting yarn, btw.
Of course you can use any bubble wand!
Enjoy💕
---------------------------------
How to Make Giant Bubbles that won't Pop Easily (Homemade Bubble Solution Recipe)
Difficulty: Very Easy
Time: 3min
Number of servings: 550ml
Ingredients:
1 tbsp. granulated sugar
400ml boiled tap water (high purity water is better)
100ml laundry starch PVA (you can get it at DAISO 100yen shop)
50ml dishwashing liquid (surfactant around 40% increases durability)
Directions:
1. In a bottle, put granulated sugar and water. Shake to mix well. Dissolve the sugar completely.
2. pour in laundry starch and dishwashing liquid, then shake gently to mix.
レシピ(日本語)
https://cooklabo.blogspot.com/2021/09/Giant-Bubbles.html
---------------------------------
Music by
YouTube Audio Library
Follow me on social media. If you have recreated any of my food, you can share some pictures #ochikeron. I am always happy to see them.
♥FOLLOW ME HERE♥
http://instagram.com/ochikeron/
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
♥My COOKBOOK available on Amazon Kindle♥
http://amzn.to/2EwR3ah
NO MORE hard copies... those who got one are lucky!
♥More Written Recipes are on my BLOG♥
http://createeathappy.blogspot.com/
♥My Recipe Posts in Japanese♥
http://cooklabo.blogspot.jp/
http://cookpad.com/ami
http://twitter.com/alohaforever
♥and of course PLEASE SUBSCRIBE♥
http://www.youtube.com/user/ochikeron?sub_confirmation=1
can i user 在 ochikeron Youtube 的最佳貼文
You just need Tempura flour and mayonnaise.
Double or triple this recipe to make as many as you want 😊
Whipped cream or ice cream filling is really good. It adds vanilla flavor and sweetness. Makes it moist and super delicious. Must try!
French Crullers are the top-selling donut at Mister Donut (donut shop) in Japan. Simple sugar glaze is my kids' favorite but in this video they ended up playing with the cream 😅
FYI: Tempura Flour (any brand is OK):
https://amzn.to/3BXYIMp
---------------------------------
2-Ingredient French Crullers
Difficulty: Very Easy
Time: 15min
Number of servings: 3 (3-Inch-round 1.5-Inch-height)
Ingredients:
160g (5.6oz.) Tempura flour https://amzn.to/3BXYIMp
4 tbsp. mayonnaise https://amzn.to/3yTRmHX
100ml water
deep frying oil
powdered sugar (confectioner's sugar)
whipped cream
Directions:
1. Put Tempura flour, mayonnaise, and 100ml water in a bowl and mix well with a spatula.
2. Transfer the batter into a pastry bag fitted with a large (0.6inch) star tip (Do NOT use a round tip or the batter will explode!!!). Pipe out 2 layers of rings onto a parchment paper.
3. Deep fry in oil at 180C (350F) until crisp golden brown.
4. Dust with powdered sugar or drizzle with sugar glaze (mix 3 tbsp. powdered sugar & 1 tsp. water). You can slice and place whipped cream or ice cream between the layers if you like!
I haven't tried but I think you can bake in oven at 180C (350F) for 15 minutes.
↓レシピ(日本語)
https://cooklabo.blogspot.com/2021/09/Frenc-Crullers.html
---------------------------------
Music by
YouTube Audio Library
Follow me on social media. If you have recreated any of my food, you can share some pictures #ochikeron. I am always happy to see them.
♥FOLLOW ME HERE♥
http://instagram.com/ochikeron/
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
♥My COOKBOOK available on Amazon Kindle♥
http://amzn.to/2EwR3ah
NO MORE hard copies... those who got one are lucky!
♥More Written Recipes are on my BLOG♥
http://createeathappy.blogspot.com/
♥My Recipe Posts in Japanese♥
http://cooklabo.blogspot.jp/
http://cookpad.com/ami
http://twitter.com/alohaforever
♥and of course PLEASE SUBSCRIBE♥
http://www.youtube.com/user/ochikeron?sub_confirmation=1
can i user 在 Your browser is up to date - YouTube 的推薦與評價
Your browser is up to date. You can use YouTube's latest features! Opera · Mozilla Firefox · Google Chrome · Browse YouTube · About · Copyright · Contact us ... ... <看更多>
can i user 在 Test Users - App Development - Documentation - Facebook 的推薦與評價
Unlike Testers, who are real people who have been granted a Tester role on your app, test users are simulated Facebook user accounts that you can use to test ... ... <看更多>
can i user 在 How to detect Safari, Chrome, IE, Firefox and Opera browser? 的推薦與評價
... <看更多>
相關內容