📜 [專欄新文章] EIP2929, EIP2930 簡介
✍️ Anton Cheng
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Opcode 加油Proposal,會不會讓以太坊變更貴呢
昨天在同事的推薦下發現了這個YouTube系列:Peep an EIP,也聽了Vitalik和Martin介紹EIP2929 + 2930的這一期。這兩個EIP都已經被列入下一次的硬分岔(Berlin Hardfork),所以我就來寫個學習筆記。先打個預防針,本人對EVM可以說是非常不熟,但也希望藉著這個機會逼自己學習,如果有錯誤的話也希望懂的更多的各路大神可以不吝賜教。
Berlin without hardfork. (By Claudio Schwarz on Unsplash)
EIP2929: Gas cost increases for state access opcodes
乍看之下這是一個極為恐怖的Proposal。在Gas已經高到爆炸的2021年,理論上不應該再通過這種「加油」類的方案。不過不用緊張,其實這個EIP真正改變的是第一次access的價格,如果一筆交易內要執行一樣Opcode動作輛次,那麼gas cost 將降低為100。
Increases gas cost for SLOAD, *CALL, BALANCE, EXT* and SELFEDESTRUCT when used for the first time in a transaction.
大家都知道,合約最終會被Compile成一堆Opcode,這些Opcode也是用來計算最終交易手續費的依據:理論上越是花時間的的Opcode,應該要收越高的手續費。
但是一直以來,state access opcode 太便宜都是一個已知的問題:在2016年的上海DOS攻擊中,其中幾個攻擊的手法就是透過惡意交易大量讀取帳戶資訊、大量的創造合約再銷毀,或是不斷用 EXTCODESIZE 來讀合約大小等等,讓Client必須花大量的IO資源處理交易(需要讀寫disk的動作特別慢),最終使Client程式Crash或是延長出塊時間。儘管大部分的弱點已經透過EIP150中大量提升gas cost獲得改善(還有其後的EIP1884),但在EIP2929中,也引用的這篇Paper的數據:現在replay所有以太坊上的交易,當時那些惡意交易中的worst case還會需要~80秒才能完成。這跟以太坊所定義的13秒出塊時間有著很大的差距,也代表這個潛在的攻擊是可行的。
透過增加這些opcode所需要的gas cost,可以降低每個區塊最大可能的讀取數。以下是偷抄Vitalik PPT 的數據:(12,500,000 為gas limit上限)
Pre-EIP 2929:
BALANCE spam: 12,500,000 / (400 cost + 320 address size + 50 boilerplate) = 16,233 accesses per block
CALL spam: 12,500,000 / (700 + 320 + 50) = 11,682 accesses per block
SLOAD spam: 12,500,000 gas / (800 + 25 boilerplate) = 15,151 accesses per block (but of a smaller tree)
Post-EIP 2929:
BALANCE spam: 12,500,000 / (2,600 + 320 + 50) = 4,280 accesses per block
CALL spam: 12,500,000 / (2,600 + 320 + 50) = 4,280 accesses per block
SLOAD spam: 12,500,000 / (2,100 + 25) = 5,882 accesses per block
說實在的這個數據的解釋也很廢話,就是把Opcode變得用貴,能Spam的數量越少。平均來說Gas cost 變高3倍,所以之前worst case的80秒執行時間可以被下降到大概 ~27秒。
SSTORE changes
在實作層,EVM會維繫一個本筆交易讀取過所有交易的 Set。每次有尚未讀取過的slot時,就會先收取一筆 CLOD_SLOAD_COST (2100) ,然後把這個slot加入這個set中,下次讀寫就會比較便宜。
對於已經讀取過的Slot,再次寫入的Opcode SSTORE 之gas cost為會降低為
5000 — COLD_SLOAD_COST (2100) = 2900
簡單的說,單純只操作一次 SSTORE 的總gas 會維持一樣在 5000 。但如果這個slot是之前有讀過的,則寫入的gas cost就會降低。近一步來說,一個 x += 100 ,其實會變得更便宜:
Pre-EIP-2929: 800 SLOAD + 5000 SSTORE = 5800
Post-EIP-2929: 2100 SLOAD + 2900 warm SSTORE = 5000
其他Side effects
這個改動除了降低了最高能夠spam的次數以外,也降低了以太坊想要做到stateless client,理論上最大的witness 大小。其實這裡的原理跟前面很類似,下圖的表格比較的是目前使用hexary tree所需要的witness大小:若12.5M的區塊全部塞滿該Opcode的witness,理論上最大會佔多少空間。在EIP2929之後由於gas cost增加,就壓縮了最大可能的witness size.
這裡單純只比較增加gas cost後,對於max witness size的影響。影片中有提到其他許多方法旨在減少Witness bytes,包括使用binary tree而不是hexary tree,以及用Code Merklization等等。這些其他方法也能夠降低最後的Max Witness size,但跟這個EIP沒有直接相關。不過可以注意的一點是,這些其他在witness size上面的優化跟 gas cost 所帶來的優化的效果是可以相乘的,例如 SLOAD,更改gas price已經能夠讓max size 縮小2.6倍,若是改用Binary tree可以將 Witness bytes降低到 288 bytes,就會是再3~倍的優化。
對用戶的影響
依照Martin Swende 給出的數據,這個EIP對於一般交易的影響僅有提高0.3~0.4%。理由很簡單,雖然第一次access storage變貴了,但是後面幾次讀寫就會變得便宜。大部分應用的程式邏輯都是類似的幾個變數進行讀寫,因此可能有不少的動作反而會變得更便宜。一個最簡單的例子就是ERC20 Transfer,兩個餘額的 +=和 -= 都會變便宜,所以總共的花費也是變便宜的。
這其中也會對於Solidity的開發pattern有著一定程度的影響,我目前想到的影響可能有兩個:
由於多次的storage access變便宜,永遠cache state variables不再是一個最佳策略。以前我們會盡量想辦法減少寫入state storage的次數,現在可能會基於coding style考量減少一些的memory cache。
之前寫合約都會盡量避免external call,甚至會寫一些一次把所有 variable都回傳回來的笨函示,來避免多次的external calls。這有一部分原因是因為每次external call都會需要使用到 EXTCODESIZE 這個Opcode所以很貴。但如果 EXT 系列的Opcode也變得越call越便宜,那麼這個一次全部call 回來cache 住的pattern也可能改變。
以上兩個想法都還沒有經過實證,如果之後看到更有證據的分析的話,也會來這裡分享。
EIP2930: Optional access lists
EIP2929可能會影響一些鏈上的合約,因為有些合約有hardcode external call的gas 上限。對於這方面的問題,EIP2930提出一個新的交易類型,讓交易中多帶一個access list,即所有這筆交易即將讀寫的storage slot,並且先幫忙付掉第一次讀寫的gas,而真正交易讀寫該storage時,只會被要求付100 gas。
這不但可以避免這次EIP2929帶來的副作用,也可以被使用在其他因為gas price 改變的硬分岔升級而壞掉的合約,例如在EIP1184 增加 SLOAD gas price 時影響到的 Aragon 和Kyber 等等。儘管當時升級前各大專案都有幫助用戶提出migration 方案,但如果有人曾經卡錢在裡面,也可以Follow一下這次柏林Hardfork。
小結
新的一年就用一篇簡單的文章來開頭。最近發現自己以前的學習習慣有點亂無章法,所以新年整理了reading list,逼自己做筆記,順便發想一些想要寫的主題。今年的期許就是學更多Ethereum底層一點的知識,當然還有上層一點Defi的知識。也歡迎大家分享一下自己都是怎麼follow這麼多東西的><
EIP2929, EIP2930 簡介 was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有2部Youtube影片,追蹤數超過47萬的網紅BrandonTan91,也在其Youtube影片中提到,2,147,483,647 has been the known maximum value for a 32-bit signed binary integer in a few games. Pokémon GO is one of them as we find that out after ...
100 in binary 在 Vũ Hạ JP Facebook 的最佳貼文
Có một bài viết rất hay của Anh Trai Sato , nếu ai mà chịu đọc 100 lần và ngẫm nó thì chắc chắc chiến thắng trong thị trường Binary Option.
Tiếc rằng số đông lại không đọc, không chịu hiểu. Thực chất khi bạn trading hay nghe theo chuyên gia đọc lệnh thì bạn cũng đang chiến đấu với con người trong chính mình.
Hãy đọc kỹ bài viết bên dưới 👌
__
Bạn có thể biết tất cả Phương Pháp phân tích giao dịch. Nhưng nếu bạn không giữ được Kỷ Luật.
Thì bạn sẽ cháy tài khoản còn nhanh gấp trăm lần người không biết Phương Pháp nào.
Trade thật ra là quá trình Đấu Tranh Chiến Thắng chính bản ngã của mình (Tham Sân Si Hận) chứ ko phải là Đấu với thị trường (Market) đâu nhé.
———————
Tặng các bạn 1 Kỹ Thuật + Kỷ Luật quản lý vốn trong Wefinex bao thắng nếu đánh dài hạn.
1. Chia vốn ra làm 100 lần.
Ví dụ: 1000$ chia làm 100 lần 10$
2. Tiền để hết ở Ví Chính - Tuyệt đối ko chuyển hết vào ví Trade (tránh ấn nhầm all in và tránh máu điên nổi lên all in)
3. Mỗi phiên Trade chỉ được phép chuyển 2% vào ví Trade (98% vẫn để Ví Chính).
4. Nếu đánh thua hết 2% dừng Trade tắt máy đi Xây Hệ Thống Đại Lý kiếm thêm Thu Nhập Thụ Động (tháng có 1000$ tới 100.000$ đơn giản)
5. Nếu bắt đúng sóng (đúng Trend xu hướng) từ 2% mà đánh thắng Thông thì cứ ăn thoải mái đến 5% - 10% - 20% cho tới N%.
6. Nếu gãy cầu thua 1 lệnh dừng Trade ngay ko đánh nữa. Rút hết Lãi về Ví Chính chỉ để lại đúng 2% để Trade phiên sau.
7. Đổi Lãi Đã Thắng ra Bitcoin hoặc Eth chờ cuối năm 2020 - 2021 tăng mạnh (halving) để X Nhân nhiều lần số đã Lãi.
- Ví dụ Trade Lãi 1000$ thì cuối năm tăng thành 2000$ hay 4000$.
8. Kỷ Luật tuyệt đối chỉ cho phép thua 2% một phiên còn Thắng Thông thì thoải mái N% cũng được. Gãy cầu thắng 1 lệnh nghỉ ngay giữ Thành Quả.
9. Đánh Kỷ Luật đủ 100 Phiên như vậy. Nếu tỷ lệ thắng thua = nhau là có 50 phiên thua và 50 phiên Thắng. Khi thua thì 2% và khi thắng thì N% thì dài hạn tính theo Tuần theo Tháng bao kiếm đủ tiền cho vợ đi chợ nhé.
10. Lưu ý trong xác xuất có thể bạn Ko May thua 5 Phiên liền hay bạn Đỏ thắng 5 phiên Thông là Bình Thường.
Ko Tham Sân Si Hận. Tất cả chỉ là bài toán Xác Suất. Quan trọng nhất vẫn là Kỷ Luật.
Chốt: Trade thật ra là quá trình Đấu Tranh Chiến Thắng chính bản ngã của mình (Tham Sân Si Hận) chứ ko phải là Đấu với thị trường (Market) đâu nhé.
#We_finex kiếm tiền theo từng tích tắc ⏰
Vốn : 4,8 Tr ib vào việc !
100 in binary 在 AppWorks Facebook 的最讚貼文
Interview with A Founder: Conor McLaughlin (Co-founder of 99.co)
By David Wu (AppWorks Associate)
Conor McLaughlin was previously the Co-founder and CTO of 99.co, the real estate marketplace in Singapore and Indonesia. He spent six and a half years at the startup, whose backers include Sequoia Capital, 500 Startups, and Facebook co-founder Eduardo Saverin, helping to grow it into a $100 million company. As a member of AppWorks Accelerator #21, he is currently working on his next big project, a yet-to-be-named language learning startup.
【What advice do you have for first-time founders?】
First, you need to decide: do I want to run a sprint or a marathon? For a sprint, you may be open to acquisition from the beginning, delay non-startup aspects of your life, give yourself two years where you drop everything to test an idea, choose to raise more money earlier on and thus be more diluted, or do anything else that implies a shorter time horizon. Typically 1-5 years - this can lead to a major boon in a short period of time if executed well. If you decide you are in the sprinting business, you will most likely be pushed toward binary outcomes because of how many investors and employees you have on your cap table. As a first-time founder, you need to be clear with yourself on what you are willing to put on the line. As Reid Hoffman says, it’s like jumping off a cliff and building a plane on the way down… hopefully you build a plane in time.
If you are running a marathon, you are deciding that your competitive advantage is consistency over intensity. You are in this for 10, 15 years. With this time horizon, you will realize you need ways to metabolize stress and maintain emotional, spiritual, and mental health. You need to maintain relationships with friends, family, and romantic partners. When you are looking at this 10 year period, you realize the people around you can only put up with so much. Unfortunately, while work is something people can generally bounce back from, there are many things in life where you cannot - an example is your relationship with your partner. If you’re going to run a marathon, you need to be clear with yourself about what time you have for other aspects of your life and what time you have for your company. Eventually you need to learn what the right speed is where you can run as long as possible. It’s amazing how often it is that those people that keep going, assuming you have chosen the right problem to solve, eventually find daylight. Part of that is just lasting long enough.
Second, you need to revisit and continually ask yourself: should I still be running a sprint or a marathon? Circumstances change. Maybe you sprinted for the first two years to secure interesting results and funding; now it's time to transition to a marathon and clean up the life debt a bit. Or inversely, maybe you're finally leaving the trough of sorrow and it's time to sprint for a bit. Most founders will be in a long distance race with periodic sprinting. From my observation, founders most often stop because of two reasons: They either A) run out of money or B) run out of energy. There’s plenty of advice out there for scenario A (hint: don’t). But in my experience, scenario B is far more pernicious and dangerous to would-be successful founders. If you are in a marathon but fail to pace yourself and run it like one long sprint, you are unlikely to make it to the end.
Much founder advice speaks to this: Don’t let your startup make you fat. Exercise 5-10% of the time. Pick up a hobby outside of your startup. Go home for holidays. All of it leads back to one thing: You need to take care of yourself. Because injury will be far worse for your progress than being a little slower. “Slow is smooth, smooth is fast”, as the US Navy Seals say. This is surprisingly difficult advice for intrinsically motivated founders to follow, because in the event of failure, it makes them vulnerable to the thought, “Well, you didn’t work hard enough.” But for those that already have the hustle, your job is to avoid the moment of epiphany where you look in the mirror and think, “This isn’t worth it.”
All founders will have to sacrifice some things. The point is to not sacrifice everything. It will make you more resilient. Not less. It will give you the space to see situations more objectively and make better decisions. And most importantly, it will let you love what you do because it will remind you that the work isn’t just in service of yourself, it’s in the service of others. I do not think you can judge hard work over a day, or even a year, but I do think you can judge hard work over 5-10 years. Hard work is not just about the next 1-2 months. There will be times when you need to run as fast as possible, but if that is happening all the time you are probably not being smart about the situation. So don’t hurt yourself, be consistent, keep disciplined, and keep going.
Lastly, focus on your metaskills. Public speaking, reading, writing - skills applied in every aspect of your life. Generally what they reflect is learning how to think better. As a founder you need to think about - how can I think more clearly, be more creative, rigorous, analytical? As Warren Buffett and others have said: I have never seen a successful person that did not read as often as they could. Actual books and long form scare a lot of people. That’s your competitive advantage. Read blog posts from smart people, follow smart people on Twitter, listen to podcasts. Always be focused on how you can develop yourself to think better. Fostering the habit of improving your thinking will foster discipline in yourself. And discipline will let you turn that rigorous thinking into action.
【I imagine running the “race” has been especially tough this year. How have you gotten through 2020?】
I have leaned on routine and community. I’ve spent a lot of time trying to foster discipline in myself. I make my bed every morning, meditate every morning, make sure that I go to the gym 3-4 times a week. There’s so much uncertainty in both the world and the entrepreneurial space. Keeping certain things consistent gives me a spine to my life that I can fall back on. If I’m not feeling well, my discipline takes over and I’ll go to the gym. That helps me relieve stress - falling back to routine and having some mainstays of consistency and structure.
And community - it’s been the big mental health zeitgeist of this year. Everyone is recognizing that without the people around us, our mental health diminishes. Joining AppWorks was very intentional so I could surround myself with like-minded people who could question me, hold me accountable, and inspire me. And also just forming personal connections where I felt that I was still taking care of my mental health by connecting with others. Being a founder is an incredibly lonely journey. In the early days, there’s not a lot of people around. Later, when you do hire lots of people, you need to be the boss, the leader - for certain things, you can’t tell the employees everything, and even if you do, there will always be a bit of distance. You need people to relate to - people want to be seen for who they are, and appreciated for what they give. When you are a founder, sometimes it’s hard to feel that you are seen. So I intentionally put myself in situations where I can be inspired, be held accountable, and more importantly connect with others, and feel that I’m not alone. And that me and my co-founders are part of a communal journey with those around us.
【When you talk about how to run the race, I get the sense that you’re drawing from previous experiences and, perhaps, mistakes. What are the mistakes you’ve made in your founder journey and the takeaways?】
I think you could take a calendar, point to a random week, and we could list out all the mistakes from that week (laughs). I do subscribe to Steve Jobs’ philosophy: mistakes will happen, but mistakes happening means we are making decisions. Not making decisions is perhaps the biggest mistake. It’s often the reason for frustration, loss of speed, loss of momentum - so many of the issues you encounter in startups. Not making enough mistakes is probably the #1 mistake that I’ve made.
Second, going back to my advice to first-time founders, is not understanding what game I’m playing. Not understanding that all the money in the world is not going to be worth it if your spouse or partner decides to leave you because you have relegated them to a second-class citizen in your life. I think I forgot that at points. There is more to life than just the company.
Third, be careful about who you choose to work with. At minimum, if you’re doing a standard 8-9 hours at the office five times a week, that’s a lot of time with those people. You want to like the people that you work with - you want to know they’re high integrity, you want to respect their values, and you want to have common values. Choosing the right people that give you energy rather than take it away just makes running the marathon so much easier.
【We welcome all AI, Blockchain, or Southeast Asia founders to join AppWorks Accelerator: https://bit.ly/3r4lLR8 】
100 in binary 在 BrandonTan91 Youtube 的精選貼文
2,147,483,647 has been the known maximum value for a 32-bit signed binary integer in a few games. Pokémon GO is one of them as we find that out after reaching that number for the Experience Points (XP).
Join me as I travel, eat and play Pokémon GO the way a local trainer would in their own country and city. Visiting one country and one city at at time through Pokémon GO.
Subscribe if you would like to watch my Pokémon GO travel adventure as I visit different countries, cities and communities, https://tinyurl.com/y65jruw2
Social:
Instagram: https://www.instagram.com/brandontan91/
TWITTER: https://twitter.com/brandontan91
Vlogging Set-Up:
Camera - Sony RX 100 Mark 7
Mic - Rode VideoMicro
Screen Recorder - iPad Mini 5
Pokémon is Copyright Gamefreak, Nintendo and The Pokémon Company 2001-2016
All images and names owned and trademarked by Nintendo, Niantic, The Pokémon Company, and Gamefreak are property of their respective owners.
![post-title](https://i.ytimg.com/vi/2WeonJv4_iY/hqdefault.jpg)
100 in binary 在 XSX Automotive Photography Youtube 的最讚貼文
Click link để nhận ngay 1000$ thử nghiệm: https://goo.gl/vpN4B8
*Miễn trừ trách nhiệm:
-Video được tài trợ bởi Binomo - sàn giao dịch điện tử online.
-Chỉ tham gia đăng kí khi bạn đủ 18 tuổi và biết mình đang làm gì!
*Disclaimer:
-This video is sponsored by Binomo - a binary options broker
-Only register if you are over 18 and know what you are doing!
Các bạn thấy hay nhớ bấm like, subscribe và click quảng cáo ủng hộ mình nha :).
Nếu được, hãy donate cho mình tại: http://unghotoi.com/xuansieuxe, để giúp mình làm ra video tốt hơn nhé, cảm ơn các bạn nhiều ^^.
Fanpage: https://fb.com/XSXphoto
Youtube: https://youtube.com/bienphananhxuan
Instagram: xsxphoto
Flickr: https://www.flickr.com/bienphananhxuan
![post-title](https://i.ytimg.com/vi/Ss36FihfTrg/hqdefault.jpg)