📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有4部Youtube影片,追蹤數超過25萬的網紅13N,也在其Youtube影片中提到,買二手車都是個風險,現場看也會怕自己沒注意到重大缺失,或賣家刻意隱藏問題。自己沒把握的情況,當然是帶車先去車店給技師檢查。找個信賴的店家幫忙也可省下不少麻煩。It's always a risk when buying used bike. I am always scared that I mig...
「bring up the issue」的推薦目錄:
- 關於bring up the issue 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於bring up the issue 在 管碧玲 (kuanbiling) Facebook 的最讚貼文
- 關於bring up the issue 在 Victor Chau Yoga Facebook 的精選貼文
- 關於bring up the issue 在 13N Youtube 的精選貼文
- 關於bring up the issue 在 ochikeron Youtube 的最讚貼文
- 關於bring up the issue 在 ochikeron Youtube 的最讚貼文
- 關於bring up the issue 在 戴爾美語- 【片語補給】 Bring up 提出(議題) EX:The issue ... 的評價
- 關於bring up the issue 在 What is it called when you raise a problem and someone else ... 的評價
- 關於bring up the issue 在 Bring up, Bring down - English phrasal verbs - YouTube 的評價
- 關於bring up the issue 在 Please bring up scrolling in a window again #8928 - GitHub 的評價
bring up the issue 在 管碧玲 (kuanbiling) Facebook 的最讚貼文
建立全球視野的國際觀,才能拯救國民黨自卑自作賤的人格!
美國「外交」雜誌最新一篇報導,說明G7領袖聯合公報中納入台海和平安全的議題,代表「台灣海峽的危機將影響歐洲利益」的意識,越來越高漲。這篇名為:The EU’s Stake in the Taiwan Strait Issue(歐盟在台海問題上的利害關係)的報導,並說明讓七國同意這個議題被列入並不容易,內幕是:德國、法國的先頭部隊不敢決定,是到最後一天早上,才達成共識的!
報導最先指出這個聲明的意義說:「最新聲明表現岀一個海峽危機將能影響歐洲利益的意識越來越高漲」(Recent statements reflect growing awareness of how a crisis in the strait would impact European interests.)。
文中,整理出關注台海問題的用語,不斷出現的大事紀。這個句子是「我們強調台海和平穩定的重要性,並鼓勵和平解決兩岸問題」(We underscore the importance of peace and stability across the Taiwan Strait, and encourage the peaceful resolution of cross-Strait issues.)
這簡潔的句子首次出現在6/13 G-7高峰會公報中;
兩天後(6/15),同樣的內容也首次出現在歐美高峰會的共同聲明。
除此之外,強調台海和平與穩定的重要性,在2021 Q2幾個最高層級的聯合聲明中不斷出現,包括:
六月的澳日2+2國防外交、
歐盟-日本高峰會、
美韓高峰會、
五月的G7外交行動部長會議、
四月的日美高峰會議。
今年的G7,目標是肺炎大流行的恢復及「重建要更好」,十分受到關注,世界各地的政治領袖全都在密切關注:美國新政府及其合作夥伴如何就議程進行談判。 包括什麼議題將成為他們的共同優先事項。
這段內幕的原文,提供大家參考:
The inclusion of the Taiwan Strait issue as a shared agenda item – under the “Global Responsibility and International Action” heading – was not an easy decision among the seven capitals. According to political and diplomatic sources cited by a Tokyo-based news agency, before the summit, the G-7 sherpas of France and Germany argued that since the Taiwan Strait issue had been touched upon clearly in the Foreign Ministers’ joint statement a month ago already, it might not be necessary to bring up the issue in the leaders’ communiqué. France and Germany were looking to mitigate the irritations to Beijing. The U.S. and Japanese representatives, on the other hand, suggested the necessity of such a move, arguing that the situation in the Taiwan Strait is a topic closely linked to their national security and that failing to mention it would deliver the wrong impression that the leaders collectively have no concerns over the issue. The sherpas thus left the decision to the heads of state and government over the course of the summit. It was not until the morning of the last day of the summit that French President Emmanuel Macron and German Chancellor Angela Merkel agreed on including the Taiwan Strait issue in the communiqué.
歐盟和美國對中國的威脅認知、安全利益和採取應對措施,並不總相同。 然而,台海和平穩定確實符合歐盟的價值觀和利益。
報導指出:台海問題提供了絕佳機會,讓大西洋兩岸共同維護共享的民主價值觀、促進印太地區的和平與繁榮,並共同應對北京的強硬行為。在台海問題上的堅定承諾的確符合歐盟的對中戰略。
支援和參與台海和平穩定,並不代表為了對抗中國選擇美國。 這恰好擺明歐盟致力於維護其價值觀和捍衛其利益的態度,是與其對中戰略一致。
(A firm commitment with regards to the Taiwan Strait issue is indeed in line with the EU’s strategy on China.
Endorsing and engaging in peace and stability in the Taiwan Strait does not mean choosing the U.S. side in order to counter China. It is rather an illustration of the EU’s dedication to uphold its values and safeguard its interests, which is in concert with its own China strategy.)
台灣議題躍上G7領袖聯合公報,全世界都在關注,這是歷史新頁!如果台灣不被視為一個民主自由而強盛互助的夥伴,歐洲不會這麼理直氣壯的敢於得罪中國。
台灣人民如果有普遍的世界觀,能夠用足夠的高度肯定自己,反對黨就不敢自作賤的把台灣當作乞丐了!
國家最大的反對黨沒有國際觀,是多麼驚人的事?當G7和台灣分享共同的民主價值觀、並視為印太和平與繁榮的一環,國民黨人卻認為台灣是乞丐,強國在施捨!我深深以為,只有建立全球視野的國際觀,才能拯救國民黨自卑自作賤的人格!
https://thediplomat.com/2021/06/the-eus-stake-in-the-taiwan-strait-issue/?fbclid=IwAR1BhBel8XpeZaLGEyL9altWPQ2WIbjNXCqPObC6yadJM4bOi8dc0DmxvaY
bring up the issue 在 Victor Chau Yoga Facebook 的精選貼文
How many types of #headstand can you see?
#sirsasana, a.k.a “king of all asanas” might come in different shapes or form. Sometimes you do leg variations, sometimes it’s the hands. And sometimes you don’t even need your hands at all! I love how this set up where can use the blocks to support your own body. Follow these steps if you wanna try:
1. You’d need at least 4 blocks but ideally 6 and a clear wall space.
2. Set up the blocks as pictured. But how high the blocks really depend on the length of your head 👽 and your neck 🦒.
3. Come to the wall as close as you can and bring the head between the blocks. The head doesn’t even have to touch the floor - so it’s great for those who have a neck issue and can normally not do a headstand.
4. Hands on the floor in front of the blocks and lift the legs (or kick them up). Stick the back to the wall. Keep the hands on the floor if you’re new to this.
5. Suck the belly in and keep breathing. I normally stay here for 1-5 mins and have a good 1-2 min of child’s pose. It’s my #espresso ☕️
Of course, have someone to spot you if you need extra help staying in headstand.
I’ve been practicing headstand for at least 13 years now and it has kept my youthful looks 👶🏻. What other benefits can you think of?
#vinyasayoga #victorchauyoga #yogapractice #yogateaching #yogaworkshop #yogahk #hongkongyoga #empowerment #yogachallenge #igyogachallenge #igyogacommunity #inversion #yogapose #yogaprogress #yogalife #yogajourney #yogalifestyle #yogagram #empoweredflow
bring up the issue 在 13N Youtube 的精選貼文
買二手車都是個風險,現場看也會怕自己沒注意到重大缺失,或賣家刻意隱藏問題。自己沒把握的情況,當然是帶車先去車店給技師檢查。找個信賴的店家幫忙也可省下不少麻煩。It's always a risk when buying used bike. I am always scared that I might miss something when looking at a bike in person. Besides, some seller might be shady enough to completely hide the issue from potential buyer. If you are not confident enough to purchase, always bring the bike in for inspection first. It saves a lot of headache when you have a trusting shop to help out.
MotoVlog 157 摩托日記第一百五十七篇
Outro Music: Trixtor - Just This Once
bring up the issue 在 ochikeron Youtube 的最讚貼文
♥My COOKBOOK available WORLDWIDE レシピ本もよろしくね♥
https://www.amazon.com/dp/4046014822/
http://www.amazon.co.jp/gp/product/4046014822/ref=as_li_ss_tl?ie=UTF8&camp=247&creative=7399&creativeASIN=4046014822&linkCode=as2&tag=shopping072-22
Amazon Japan may be Cheaper ($10 plus shipping fee).
How to Order My Cookbook from Amazon Japan:
https://www.youtube.com/watch?v=mWsrMmA7AnI
Old version is unlisted since it has a copyright issue.
過去にアップしたものは著作権の都合上限定公開になっているので編集し直しました。
https://www.youtube.com/watch?v=Y8kS3zj-BxY
Osechi-Ryori is traditional Japanese New Year's food eaten during the first three days of the New Year. Each dishes that make up Osechi-Ryori has a special meaning celebrating the New Year (such as good health, fertility, good harvest, happiness, long life, etc...) and those dishes can last for a couple of days in the refrigerator or at cool room temperature in winter. Usually, they are served in Jyubako (重箱: three-tiered bento boxes). In the first tier, we serve colorful festive dishes such as shrimp, black beans, sweet chestnuts, etc... In the second tier we serve Sunomono (pickled dishes) and Yakimono (grilled dishes). And in the third tier, we serve Nimono (simmered dish) called Nishime (simmered Japanese vegetables).
Traditionally, we spend few days to prepare Osechi-Ryori but I always spend few hours to complete mine. I use ready-made dishes for sweet dishes since my darling doesn't eat a lot. I put more effort into cooking the savory dishes.
So, this is my darling's favorite Nishime recipe for the third tier :) I use frozen Japanese vegetables to save time and money. I came up with this idea when I lived in New York, where you can not find ingredients easily. I hope you can make it in your country in this way.
For the seasoning, I used Yamasa's Konbu Tsuyu (3 times concentrated Konbu kelp seaweed soup stock) which is tasty and convenient. I'm sure it is available overseas at Asian grocery stores or online.
Yamasa Konbu Tsuyu ヤマサ 昆布つゆ
3 times concentrated Konbu kelp seaweed soup stock
http://astore.amazon.co.jp/shopping072-22/detail/B00Z607H6Y
http://www.yamasa.com/konbutsuyu/product/index.html
In the end of the video, I will show you my Osechi-Ryori from past years! Don't miss them!
---------------------------------
Easy Nishime (Simmered Japanese Vegetables)
Difficulty: Easy
Time: 1hour
Number of servings: 5
Necessary Equipment:
1 large deep pot
1 medium pot
1 small pot
1 Otoshi But a (drop-lid - you can also use aluminum foil)
Ingredients:
1 large chicken thigh
250g (8.8oz.) Konnyaku
400g (0.9lb.) 1 bag of frozen Japanese vegetables (includes: taro potatoes, lotus roots, carrots, Shiitake mushrooms, green beans, bamboo shoots, burdock roots)
5 decoratively cut Shiitake mushrooms
1 Yurine (lily bulb)
5 decoratively cut carrots
A
* 3 tbsp. soy sauce
* 1 tbsp. Mirin (sweet Sake)
* 1 tbsp. Sake
* 1 tbsp. sugar
B
* 20ml 3 times concentrated Yamasa's Konbu Tsuyu
* 80ml water
C
* 30ml 3 times concentrated Yamasa's Konbu Tsuyu
* 120ml water
Directions:
1. Thinly slice or decoratively cut Konnyaku, and boil 2-3 minutes to remove bad smell.
2. Cut the chicken into bite-sized pieces, parboil to remove the fat, drain, and set aside.
3. Separate the frozen vegetables and keep frozen until just before you use them. NOTE: you don't need to use carrot and Shiitake mushrooms if you prepare decoratively cut ones.
4. In a large deep pot, put Konnyaku, chicken and Shiitake mushrooms. Add enough water to cover the ingredients, bring to a boil, then add A.
5. Cover with Otoshi-Buta (drop-lid - you can also use aluminum foil) and cook on low for 20 minutes.
6. Add lotus roots, bamboo shoots, burdock roots, and simmer uncovered for 15 minutes.
7. Wash Yurine and separate into pieces. In a small pot, bring water to a boil, cook the Yurine pieces for a minute, quickly rinse with cold water, then drain. Bring B to a boil, add the Yurine pieces, and cook for 3 minutes.
8. In a medium pot, bring C to a boil, add taro potatoes and cook for 5 minutes. Add decoratively cut carrots and cook for another 5 minutes. Add green beans and cook for 2 more minutes.
9. In the third tier of Jyubako (three-tiered bento boxes), nicely arrange 6, 7, and 8 (drain excess liquid).
レシピ(日本語)
http://cooklabo.blogspot.com/2010/11/blog-post_09.html
---------------------------------
Music by
SHWフリー音楽素材
ohka_japan
http://shw.in/
♥Utensils I use in my videos♥
http://astore.amazon.co.jp/shopping072-22
♥FOLLOW ME HERE♥
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
http://instagram.com/ochikeron/
♥Visit my Blog to know more about ME♥
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
bring up the issue 在 ochikeron Youtube 的最讚貼文
♥My COOKBOOK available WORLDWIDE レシピ本もよろしくね♥
https://www.amazon.com/dp/4046014822/
http://www.amazon.co.jp/gp/product/4046014822/ref=as_li_ss_tl?ie=UTF8&camp=247&creative=7399&creativeASIN=4046014822&linkCode=as2&tag=shopping072-22
Amazon Japan may be Cheaper ($10 plus shipping fee).
How to Order My Cookbook from Amazon Japan:
https://www.youtube.com/watch?v=mWsrMmA7AnI
Old version is unlisted since it has a copyright issue.
過去にアップしたものは著作権の都合上限定公開になっているので編集し直しました。
https://www.youtube.com/watch?v=NoGnR--7kQY
I made up this idea. Kabocha Sashimi does not exist, but it is very addictive and super delicious!!! Some people asked me how it tastes like. It is just like eating avocado with soy sauce ;) hehe
I used Kanten (agar agar powder) to firm up the Kabocha (Japanese Squash). Kanten contains a lot of fiber. It cleanses your digestive tract and cures constipation. Good for your health!
Kanten (agar agar powder) is a coagulant extracted from a seaweed called Tengusa. It is different from gelatin that you have to boil it until the boiling point, or it won't firm up!
FYI:
Kanten (Agar Agar Powder)
http://astore.amazon.co.jp/shopping072-22/detail/B003Q46ZE2
Wasabi
http://astore.amazon.co.jp/shopping072-22/detail/B00Z5XE35U
---------------------------------
Kabocha (Japanese Squash) Sashimi
Difficulty: Easy
Time: 20min + 60min cooling time
Number of servings: 4
Necessary Equipment:
mesh strainer
Ingredients:
400g (14oz.) Kabocha (Japanese Squash)
200ml soy milk (you can use milk)
4g (2 tsp.) Kanten powder (agar-agar powder)
soy sauce
Wasabi
Directions:
1. Scoop out the seeds of Kabocha and microwave on medium (500W) for 3 minutes to make it easy to cut.
2. Cut Kabocha into large chunks and remove the skin. Place them in a microwavable dish, cover with plastic wrap, and microwave on medium (500w) for 5 minutes until tender (cooked through).
3. Mash Kabocha using a fork while they are hot. Then push through the mesh strainer to strain.
4. Put soy milk and Kanten in a pot, then mix well. Bring to a boil and simmer for 2~3 minutes, mixing constantly. *Please watch carefully and turn down the heat a little bit if it starts to dry out.
5. Immediately, add the Kanten mixture into the mashed Kabocha and mix well.
6. Pour the mixture into a square container and cool in the fridge for about and hour to set.
7. Slice and serve with soy sauce and Wasabi if you like.
レシピ (日本語)
http://cooklabo.blogspot.jp/2011/08/blog-post_05.html
---------------------------------
Music by
YouTube Audio Library
Fig Leaf Rag
♥Utensils I use in my videos♥
http://astore.amazon.co.jp/shopping072-22
♥FOLLOW ME HERE♥
https://www.facebook.com/ochikeron
https://plus.google.com/+ochikeron
http://twitter.com/ochikeron
http://instagram.com/ochikeron/
♥Original T-SHIRTS♥
http://www.youtube.com/watch?v=FFsQE0qd_4w
♥Visit my Blog to know more about ME♥
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
bring up the issue 在 What is it called when you raise a problem and someone else ... 的推薦與評價
You raised a valid point, but now someone has completely dismissed it by bringing up something unrelated. A more well known example is "I'm ... ... <看更多>
bring up the issue 在 戴爾美語- 【片語補給】 Bring up 提出(議題) EX:The issue ... 的推薦與評價
【片語補給】 Bring up 提出(議題) EX:The issue will be brought up again at the next anti-pollution convention. 中:這項議題將在下次反污染會議中再次提出#台灣 ... ... <看更多>