📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有2部Youtube影片,追蹤數超過93萬的網紅Ytower Cooking channel,也在其Youtube影片中提到,鳳梨酥在家自己烤Homemade Baked Pineapple Cakes 材料:低筋麵粉325g、糖粉145g、杏仁粉260g、奶粉23g、蛋40g、奶油260g、鳳梨餡480g。 (材料為40個鳳梨酥的份量) Ingredients: 325 grams low-gluten flour,...
equal space equal 在 Fxiii 刺繡插畫 Facebook 的最讚貼文
<之間 in between>
在這之間的是我們,是現在。
In the space between history and our future lies the present.
當疫情蔓延成為全人類必須面對的共通處境時,國際間的生活圈縮小了,而每個人的世界觀卻因此放大了。在隔著山與海的土地之間,以往由距離所圍塑出的空隙,變成了各種關係中必須存在的安全空間 (距離) 。在這之間,不同關係的對等或對立也漸漸發展出各自適切的形狀。然而,在這國與國、人與人、人與自然、未來與過往之間,唯一不變的是當下,不斷變動的是正在發生和即將發生的,不穩定卻又充滿各種未知的可能。
As the pandemic spreads across the globe and becomes a common situation faced by all humanity, the international living circle has shrunk and everyone’s worldview has been expanding. On the land between mountains and seas, gaps created by distance have become necessary safe space (distancing) in between people. In such space, different equal or rival relations also gradually develop into suitable forms. However, in between states, individuals, mankind and nature, the future and the past, the only thing that remains unchanged is the present, whereas what constantly changes are unstable and unknown possibilities that are happening and about to happen.
此系列中,人類的身體是一個群眾的概念,右手跟左手能夠各自單一且獨立運作,但大多是共同合作的。藉由這些肢體代表相異的個體,交相圈出的空白是彼此的距離,透過顏色各異的經緯線交織填補了這些空洞,呈現重置的現況秩序,同時也代表正在發生的當下。
In this series, human body is conceived as a crowd. While the right hand and the left hand can operate alone and independently, they work together most of the time. These limbs that represent different individuals form blank spaces that indicate the distance in between. The interweaving colors, on the other hand, fill the blankness, showing the current order that has been reset, as well as the present that is happening.
之間 In between
1/30-8/30 @毓繡美術館
.
.
.
.
#exhibition #hand #hands #covidart #love #surrealism #lineart #linum #linedrawing #popofcolour #ink #tattooideas #hoopartwork #wallart #homedecor #seemyembroidery #embroideryart #stitchersofinstagram #illustration #stitch #textile #lifestyle
equal space equal 在 Facebook 的最佳貼文
I have a special affinity to design of the 60’s. This was the era of modernism, minimal design with an eye towards the future. 60’s sports cars expressed this with smooth rolling sexy feminine curves. The sense of speed was created by a designer’s hand rather than calculated from a computer. Modern sports cars represent speed with harsh lines and angles intersected with ducts and bits of aero highlight technology but very little romance. That’s why I was pleasantly surprised when Ferrari rolled out the all new Roma. A massive departure from their cars of recent past and even their current lineup, Ferrari brought sexy back to their line up and I was excited to get my hands on one.
As I walk around this example in an electric Blue Corsa, everything about this design gets me excited. The overhanging shark nose with a very modern and minimal grill is clean and sharp. The lack of vents or ducts allows the fenders to swoop you up and around it’s narrowed waist leading to more curved haunches that culminate with it’s glorious big, round, squat and firm booty. The purity of this design reminds me of the legendary GTO of the 60’s but also a little bit of the Daytona of the 70’s as well. Either way, the history and lineage of the brand is definitely present in this design.
The interior is characterized by a “dual cockpit design” giving equal space to both driver and passenger. A touch screen display on the passenger side instantly makes the passenger a co driver as they have audio and climate controls as well as driver info like RPM and speed. The dash is made up of a curved 16’ HD screen and can be personalized in various configurations. The steering wheel is all new, with touch controls including the start/stop function. While it is a technological feat, I’m old so I prefer physical buttons that go click. There were a couple times an errant finger had me calling people I had rather not talk to. There are two rear seats in the back that I was able to shoehorn my 7 year old daughter into for a family drive. Overall the interior is a very comfortable yet minimal space in black leather and Alcantara putting the focus on the road in front of you, where it should.
equal space equal 在 Ytower Cooking channel Youtube 的最佳貼文
鳳梨酥在家自己烤Homemade Baked Pineapple Cakes
材料:低筋麵粉325g、糖粉145g、杏仁粉260g、奶粉23g、蛋40g、奶油260g、鳳梨餡480g。
(材料為40個鳳梨酥的份量)
Ingredients: 325 grams low-gluten flour, 145 grams powdered sugar, 260 grams almond powder, 23 grams powdered milk, 40 grams egg, 260 grams butter, 480 grams pineapple filling. (Ingredients makes 40 pineapple cakes)
1.把低筋麵粉、糖粉、杏仁粉、奶粉一起過篩在白報紙上,做個粉牆把軟化後的奶油、蛋放入中間,用刮板使用按壓方式,讓麵粉整個揉成糰且不會黏手即可,如果揉太久會讓酥皮鬆散且會黏手。
2.把鳳梨餡揉成長條狀切12等份,把麵糰也揉成長條狀沾一點高筋麵粉切成12等份,用麵糰把鳳梨餡包起來揉成橢圓狀,之後放進烤模中,每一份烤模都有相等間距,這樣烤模溫度才會一致。
3.烤箱溫度為200度時間約10~12分鐘,烤完後鳳梨酥會呈現金黃色且有點離模這樣就代表熟了,就可以用夾子把烤模拿起,這樣就完成好吃的鳳梨酥。
1.Combine the cake flour, powdered sugar, almond powder, and powdered milk into the sieve and sift into a pile. Press a hole into the pile and put the softened butter and eggs into it. Using a scraper, mix the flour mixture with a pressing motion until the mixture forms a dough. Only knead long enough to form a dough that does not stick to the hand, over-kneading will cause the dough to fall apart and become sticky.
2.Knead the pineapple filling into a long strip and cut it into 12 equal parts. Roll the pastry dough into a long strip, dust with a little bit of bread flour and cut it into 12 equal parts. Wrap up the pineapple filling within the dough to form an oval shape, then press them into the baking pan molds. Space the baking molds apart with equal distance in between so that the baking temperature remains consistent between each mold.
3.Set the oven temperature to 200 degrees and bake for 10-12 minutes, or until the pineapple pastry becomes golden brown and pulls back a little from the sides of the mold. Use tongs to pick up the baking molds, and this is how to make delicious pineapple cakes.
【Facebook Ytower Fan Page】 https://www.facebook.com/ytower01/
【YTower Food Network - 3 minute cooking lesson】 https://goo.gl/XDRl12

equal space equal 在 一二三渡辺 Youtube 的最讚貼文
The figure that her motorcycle which is a beautiful woman runs is the refreshing itself, regular customer from old days of Mr. Hilo, beautiful woman,
Gemma equal to the second generation is a motorcycle of the motor scooter type (a big motor scooter) of 249cc cubic centimeter displacement. It was exhibited to the public first by Tokyo mortor show in 2007, and it was released on July 28, 2008.
There is sea bass sky wave on the big motor scooter of the displacement volume that a sea bass sells earlier, but I have a long distance between rings Gemma, and overall height is low. This is because I find comfort at the time of two rides. There are Honda fusion and Yamaha マグザム on a big motor scooter with a similar low and long concept, but a variant headlight compares the designs such as a characteristic front mask, a clutch cover and the muffler cover of the body same color with two precedence cars and is novel.
Because a backseat compares it with other motor scooters being aware of 2-passenger, and both the height of the seat and the 足置 きの height lower, the storage space is a full-faced helmet helmet one share, and it is not the class that is wide for a big motor scooter. It is common that the storage space of such a big motor scooter is established in the seat bottom, but Gemma is established before a seat and can put a helmet in and out while therefore taking it.
美人な彼女のバイク
走ってる姿は、爽快そのもの、
ミスターヒロの昔からの常連さん、
美女ですよ、
2代目にあたるジェンマは排気量249ccのスクータータイプ(ビッグスクーター)のオートバイである。2007年東京モーターショーで初公開され、2008年7月28日に発売された。
スズキが先に販売する同排気量のビッグスクーターにはスズキ・スカイウェイブがあるが、ジェンマの方が輪間距離が長く、全高が低い。これは2名乗車時の快適性を求めているからである。同様のロー・アンド・ロングのコンセプトを持つビッグスクーターにはホンダ・フュージョンやヤマハ・マグザムがあるが、異形ヘッドライトが特徴的なフロントマスク、車体同色のクラッチカバーとマフラーカバー等、デザインは先行二車と比較して斬新である。
2人乗りを意識して後席が他のスクーターに比べ座席の高さも足置きの高さも低くなっているため、収納スペースはフルフェイスヘルメット一個分であり、ビッグスクーターとしては広い部類ではない。こうしたビッグスクーターの収納スペースはシート下に設けられるのが一般的だが、ジェンマはシートの前に設けられており、そのため乗車しながらヘルメットを出し入れすることが可能である。
