-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BEP216: Implement EIP-3855 PUSH0 instruction #216
Conversation
BEP: 216 Title: Implement EIP-3855: PUSH0 instruction Status: Draft Type: Standards Created: 2023-3-30 BEP-216: Implement EIP 3855 PUSH0 instruction1. SummaryAs part of the Shanghai upgrade, EIP-3855: PUSH0 Instruction is required to be implemented to BSC. 2. AbstractIntroduce the PUSH0 (0x5f) instruction, which pushes the constant value 0 onto the stack. 3. MotivationOriginal motivation from EIP-3855: Many instructions expect offsets as inputs, which in a number of cases are zero. A good example is the return data parameters of CALLs, which are set to zeroes in case the contract prefers using RETURNDATA*. This is only one example, but there are many other reasons why a contract would need to push a zero value. They can achieve that today by PUSH1 0, which costs 3 gas at runtime, and is encoded as two bytes which means 2 * 200 gas deployment cost. Because of the overall cost many try to use various other instructions to achieve the same effect. Common examples include PC, MSIZE, CALLDATASIZE, RETURNDATASIZE, CODESIZE, CALLVALUE, and SELFBALANCE. Some of these cost only 2 gas and are a single byte long, but their value can depend on the context. Analysis has been conducted on ETH Mainnet (block ranges 8,567,259…8,582,058 and 12,205,970…12,817,405), and ~11.5% of all the PUSH* instructions executed push a value of zero. The main motivations for this change include:
To put the “waste” into perspective, across existing accounts 340,557,331 bytes are wasted on PUSH1 00 instructions, which means 68,111,466,200 gas was spent to deploy them. In practice a lot of these accounts share identical bytecode with others, so their total stored size in clients is lower, however the deploy time cost must have been paid nevertheless. An example for 2) is changing the behaviour of RETURNDATASIZE such that it may not be guaranteed to be zero at the beginning of the call frame. This was proposed as a way to chain transactions (i.e. EIP-2733). 4. SpecificationThe instruction PUSH0 is introduced at 0x5f. It has no immediate data, pops no items from the stack, and places a single item with the value 0 onto the stack. The cost of this instruction is 2 gas (aka base). 5. RationaleGas cost The base gas cost is used for instructions which place constant values onto the stack, such as ADDRESS, ORIGIN, and so forth. Opcode 0x5f means it is in a “contiguous” space with the rest of the PUSH implementations and potentially could share the implementation. 6. Backwards CompatibilityThis introduces a new opcode which did not exist previously. Already deployed contracts using this opcode could change their behaviour after this EIP. 7. Test Cases
8 LicenseThe content is licensed under CC0. 9. ReferenceMost description of this BEP refer to EIP-3855: Alex Beregszaszi (@axic), Hugo De la cruz (@hugo-dc), Paweł Bylica (@chfast), "EIP-3855: PUSH0 instruction [DRAFT]," Ethereum Improvement Proposals, no. 3855, February 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3855. |
No description provided.