📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有9部Youtube影片,追蹤數超過22萬的網紅Zermatt Neo,也在其Youtube影片中提到,For this episode, we headed down to Chicken Up to DESTROY an All You Can Eat Chicken Wing Buffet! Chicken Up is a Korean-themed restaurant located at ...
「mitigate」的推薦目錄:
mitigate 在 IELTS Fighter - Chiến binh IELTS Facebook 的精選貼文
- Chữa đề Writing thật tiếp theo thôi cả nhà ơi - Đề số 10 nhé: Some people think it is more important to spend public money on promoting a healthy lifestyle in order to prevent illness than to spend it on the treatment for people who are already ill. To what extent do you agree or disagree?
Bài mẫu:
The state spending on public health has become a widely perpetual concern. Some individuals argue that these already scarce resources should be reserved for the prevention of lifestyle-related illness. In my opinion, the government should focus more on the prevention of illnesses rather than medical treatment.
On the one hand, certain acute diseases, non-preventable regardless of governmental efforts to promote a healthy lifestyle, still need a state budget allocation for medical care. One of the primary duties of the government is to provide publicly funded healthcare to the whole population. Therefore, covering therapeutic and medical costs for those already developing symptoms of acute conditions would be a significant part of that duty, helping mitigate the financial burden associated with those maladies. In other words, a dearth of investment in treatment would be devastating patients’ individual life and wreaking havoc on overall social welfare.
On the other hand, promoting a healthy lifestyle as a prevention strategy is meant to avoid the entire economic burden of chronic diseases, affecting a significant proportion of the population. Those conditions, occurring across different life course stages, share common preventable risk factors relating to unhealthy behaviors, including poor nutrition, inadequate physical activity, and chronic heavy drinking and smoking. If left unchecked, trends in chronic diseases risk factors combined with a growing and aging population will increase the numbers of people living with chronic conditions, later causing the heavy burden of illness in patients, their families, and the community. Therefore, given a scarcity of state budgets for various public services, the government should directly provide information, including health education campaigns, or regulating information, such as limits on advertising and guidelines on food labelings. As a result, positive changes in individual lifestyle would follow, helping them withstand the ravages of time, and saving the state budget for other economically beneficial needs, such as technological investment, education, and infrastructure, rather than spending on treatment.
In conclusion, while allocating its healthcare budget in treatment, the government should promote a healthy lifestyle to avoid preventable chronic diseases due to its economic rationality.
Words: 341
----
Tháng 9 này, cùng IELTS Fighter Find your Fire - thắp đam mê, kệ Covid, học tập nâng cao kiến thức mỗi ngày nha. Các bạn cùng chờ đón cuộc thi Đại sứ IELTS Junior nè, Livestream học tập mỗi tuần và workshop online cho sinh viên siêu thú vị nữa nha. Theo dõi fanpage IELTS Fighter - Chiến binh IELTS để cập nhật thông tin nóng thường xuyên nhé.
mitigate 在 Facebook 的最讚貼文
Foreigners who live and work here contribute to our economy and society. They are very much a part of our local community.
Yesterday in Parliament, Lawrence Wong moved a motion for Singapore to stay open in a globalised world. He also asked Parliament to support the government’s management of the foreign work pass numbers, and to deplore the spreading of misinformation about FTAs like the Comprehensive Economic Cooperation Agreement (CECA) to stir up racism and xenophobia.
Our policies on foreign workers have created many jobs and opportunities. Still, Singaporeans are anxious and concerned about competition from the foreigners working here. We are addressing these concerns, and the problems caused by having a large foreign population in our midst. But as I said at the National Day Rally recently, we must remain open and welcoming to foreigners. If we turn inwards and become hostile to them, it would ruin us as a global hub and cost us investments and jobs (https://go.gov.sg/ndr2021-el).
The debate stretched past midnight. It was an important debate. At stake were not just our policies on foreigners, but the values of our society, and our confidence and resolve to face an uncertain world, and chart our way forward together.
I am glad MPs took a firm and unequivocal stance against racism and xenophobia, and firmly rejected attempts to use Singaporeans’ fears and anxieties to divide and weaken us. It bodes well for our future. – LHL
mitigate 在 Zermatt Neo Youtube 的最讚貼文
For this episode, we headed down to Chicken Up to DESTROY an All You Can Eat Chicken Wing Buffet! Chicken Up is a Korean-themed restaurant located at Buangkok that offers a host of Korean cuisine and specialises in Korean-style Chicken Wings. They offer an All-Day Chicken Wing Buffet at $25 for Men and $20 for Women with the Buffet also including Kimchi Fries, Truffle Fries and Spam Rice Balls.
The chicken wings came in original, yangnyum, soya and spicy yangnyum flavours. Each wing was huge and meticulously fried and seasoned. The concept of blandness did not exist during this buffet - in fact the wings were so flavourful that flavour fatigue kicked in very quickly after an extremely enjoyable first few wings. The winning tactic was to rotate through all the flavours to mitigate this.
The original had no sauce but was well-salted, with a rich chicken flavour and moist interior. I normally do not like yangnyum sauce for being too cloying, but this version balanced the sweetness very well. The spicy version was also not too strong but came with a noticeable kick. I enjoyed the soya version the most. It came glistening with an inviting black coating that did not disappoint on the palate. As expected from Chicken Up, it was not overpoweringly salty but right on the edge of the cliff. The Spam Rice Balls were also very good – each ball being packed with umami goodness that burst in your mouth as you chewed through. The Kimchi Fries were heavily loaded with a spicy mayo sauce with chunks of beef piled high.
This All You Can Eat Chicken Wing Buffet was extremely worth it given the cost and we certainly made the most of it. It has enough variety for you to switch around with to mitigate flavour fatigue and eat to your limit while not lacking in quality. Each wing came piping hot and crispy, made to order. The only thing missing was a good glass of soju/beer to wash down the Chicken Wings with. Head down to Chicken Up for outstanding Korean-style Chicken Wings!
Visit Chicken Up at:
Blk 277C Compassvale Link
#01-13 (Unit 2A)
Singapore 543277
Connect with us!
Facebook - https://www.facebook.com/zermattneofls
Instagram - http://instagram.com/zermattneo
http://instagram.com/teegongborpi
Use code ZERMATT for 58% off ALL Myprotein products.
For those that are interested in doing ZenyumClear™️ Aligners:
https://bit.ly/zermattneo-yt
Use code ZERMATT100 for special discount!
Hair Sponsor - Toliv Salon
5 Purvis Street, #01-03, Singapore
https://www.facebook.com/tolivboutique
mitigate 在 賓狗單字Bingo Bilingual Youtube 的最佳解答
賓狗的更多英文學習資源:https://www.zeczec.com/projects/bingobilingual
· 全英文 podcast
· 視訊家教
· 不定時線上課程
1 【overload 使變得過量】— 動詞
The new regulations were intended to prevent an overloading of the healthcare system.
We’re overloaded with work.
2 【outright 完全的】— 形容詞It is a rare outright parliamentary majority.
3【annulment 廢除】— 名詞
Indonesian fishers, environmental activists and law experts have called for the annulment of the deregulation law.
4 【alliance 同盟】— 名詞
Armenia has a security alliance with Russia.
EP118
5 【mitigate 減輕危害】— 動詞(正式)
Trees can help mitigate climate change.
簡單複習:
1)overload 使變得過量
2)outright 完全的
3)annulment 廢除
4) alliance 同盟
5)mitigate 減輕危害
mitigate 在 Zermatt Neo Youtube 的精選貼文
For this video, I headed down to Popeyes to destroy a custom-made Spicy Chicken Sandwich platter! Popeyes is a fast-food chain that originated in Lousiana, specialising in Fried Chicken and Cajun-style cuisine, and located island-wide. Popeye’s famously popular Chicken Sandwich, which was introduced in August 2019 to much fanfare and demand, has finally come to Singapore for a limited period of time.
Assembled onto my platter were 5 Chicken Sandwiches, 5 pieces of Fried Chicken, 4 Buttermilk Biscuits, 1 large Mac ’n’ Cheese, 1 large Coleslaw, 1 large Mashed Potato and 1 large Fries, together with various condiments like Ranch and Cheese sauces. Unfortunately, I ordered Chicken Tenders and a few other sides that were not given to me, making this platter smaller than I planned.
The Chicken Sandwiches were a true treat and I finally understand how they were sold out within weeks in the USA. The Chicken Sandwich came simply constructed - a lightly toasted Brioche Bun, a thick piece of fried chicken thigh, spicy mayonnaise and pickles. However, the simplicity of it allowed each component to shine brightly. The chicken was crispy, moist, tender and on the spicy side. The mayo had a hint of spiciness to it as well, but it still helped cool down the heat from the chicken. There were only 2 pickles in the Chicken Sandwich, but they were refreshing and crunchy. As someone who does not fancy pickles, I actually would have preferred more in my Chicken Sandwich. Finally, the Brioche Bun added a pleasant sweetness to mitigate the spicy chicken and mayonnaise. All these came together to form a splendid Chicken Sandwich. My single criticism would be that having a slice of cheese would have elevated this Chicken Sandwich to even greater heights.
This was a relatively straightforward mukbang which I enjoyed. My only regret was speeding through the Chicken Sandwiches which made me unable to fully enjoy them. Do try Popeye’s Chicken Sandwich while it is available here in Singapore!
For fans who would like to join me for a buffet, please DM me on Instagram (the handle is below).
Find your closest Popeyes at https://www.popeyes.com.sg/FindPopeyes.html
Connect with me!
Facebook - https://www.facebook.com/zermattneofls
Instagram - http://instagram.com/zermattneo
Use code ZERMATT for 58% off ALL Myprotein products.
For those that are interested in doing Invisible Braces:
https://bit.ly/zermattneo-yt
Use code ZERMATT100 for special discount!
mitigate 在 学个词--mitigate 的推薦與評價
mitigate 的意思是减免,减轻美国之音中文网视频- https://www.voachinese.com/a/5350132.html. ... <看更多>