From 5c9b0cc9570a23fe59e2b850ebabac1698802769 Mon Sep 17 00:00:00 2001 From: Martin Lundfall Date: Mon, 28 Oct 2019 15:13:03 +0100 Subject: [PATCH 1/5] Draft EIP: BEGINDATA opcode --- EIPS/eip-draft-begindata.md | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 EIPS/eip-draft-begindata.md diff --git a/EIPS/eip-draft-begindata.md b/EIPS/eip-draft-begindata.md new file mode 100644 index 00000000000000..e2f9c5ecc9466a --- /dev/null +++ b/EIPS/eip-draft-begindata.md @@ -0,0 +1,49 @@ +--- +eip: +title: BEGINDATA opcode +author: Martin Lundfall martin.lundfall@protonmail.com +discussions-to: +status: Draft +type: Standards Track +category Core +created: 2019-10-28 +--- + +## Simple Summary + +Introduces a new opcode `BEGINDATA`, which indicates that the remaining bytes of the contract should be regarded as data rather than contract code. + +## Abstract + +It is common for smart contracts to efficiently store data directly in the contract bytecode. Examples include constant variables, compiler metadata and the contract runtime during the init phase. Currently, such data is not distinguished from normal bytecode and is still being analysed for JUMPDESTs by EVM interpreters. This EIP introduces a new opcode `BEGINDATA` at byte `0xb6`, which marks the remainding bytecode as data, indicating to EVM interpreters, static analysis tools and chain explorers that the remaining bytes do not represent opcodes. + +## Motivation + +The `BEGINDATA` opcode has been suggested before as part of the EIP `Subroutines and Static Jumps for the EVM` [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md) as a way to determine the position of jumptables in contract bytecode. It is here introduced in its own right in order to exclude data from the JUMPDEST analysis of contracts, making it impossible to jump to data. This makes it easier for static analysis tools to analyse contracts, allows disassemblers, chain explorers and debuggers to not display data as a mess of INVALID opcodes and may even provide a marginal improvement in performance. Additionally, it paves the way for suggestions such as [EIP 1712](https://github.com/ethereum/EIPs/pull/1712) to disallow unused opcodes, jumptables [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md) and speculative proposals to disallow for deployment of contracts with stack usage violations. + +## Specification + +While computing the valid JUMPDESTs of a contract, halt analysis if `BEGINDATA` is encountered. A `JUMP` to a value higher than the `pc` value of `BEGINDATA` should throw with a `BAD_JUMP_DESTINATION` error. +If `BEGINDATA` is encountered during contract execution, it has the same semantics as `STOP`. It uses 0 gas. + +## Rationale + +The byte `0xb6` was chosen to align with [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md). +The choice to STOP if `BEGINDATA` is encountered is somewhat arbitrary. An alternative would be to `THROW`. + +## Backwards Compatibility + +The proposal will not change any existing contracts unless their current behaviour relies upon the usage of unused opcodes. + +## Test Cases + +Test cases should include: +1) A contract which jumps to a destination `X`, where `X` has a pc value higher than the `BEGINDATA` opcode, and the byte at `X` is `0x5b`. This should fail with a `BAD_JUMPDEST`. +2) A contract which encounters the `BEGINDATA` opcode (should stop executing the current call frame) + +## Implementation + +Not yet. + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From cf5868af2d42a6e671635b5cfd2a25ffd5d94323 Mon Sep 17 00:00:00 2001 From: Martin Lundfall Date: Mon, 28 Oct 2019 15:46:21 +0100 Subject: [PATCH 2/5] EIP-BEGINDATA: Add discussions-to link --- EIPS/eip-draft-begindata.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-draft-begindata.md b/EIPS/eip-draft-begindata.md index e2f9c5ecc9466a..6af460b81c0d6b 100644 --- a/EIPS/eip-draft-begindata.md +++ b/EIPS/eip-draft-begindata.md @@ -2,7 +2,7 @@ eip: title: BEGINDATA opcode author: Martin Lundfall martin.lundfall@protonmail.com -discussions-to: +discussions-to: https://ethereum-magicians.org/t/new-opcode-begindata/3727 status: Draft type: Standards Track category Core From 279b1cd2ddf022cde00d1bf2b8007004be9fa3b5 Mon Sep 17 00:00:00 2001 From: Martin Lundfall Date: Sat, 2 Nov 2019 16:05:33 +0100 Subject: [PATCH 3/5] use eip number 2327 --- EIPS/{eip-draft-begindata.md => eip-2327.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename EIPS/{eip-draft-begindata.md => eip-2327.md} (99%) diff --git a/EIPS/eip-draft-begindata.md b/EIPS/eip-2327.md similarity index 99% rename from EIPS/eip-draft-begindata.md rename to EIPS/eip-2327.md index 6af460b81c0d6b..43f3c8b649613d 100644 --- a/EIPS/eip-draft-begindata.md +++ b/EIPS/eip-2327.md @@ -1,5 +1,5 @@ --- -eip: +eip: 2327 title: BEGINDATA opcode author: Martin Lundfall martin.lundfall@protonmail.com discussions-to: https://ethereum-magicians.org/t/new-opcode-begindata/3727 From 39151601f5235e0f70b8f352e5fa1d6917f742c1 Mon Sep 17 00:00:00 2001 From: MrChico Date: Mon, 4 Nov 2019 18:59:04 +0100 Subject: [PATCH 4/5] Update EIPS/eip-2327.md Co-Authored-By: Danno Ferrin --- EIPS/eip-2327.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EIPS/eip-2327.md b/EIPS/eip-2327.md index 43f3c8b649613d..a3a94ade74daf9 100644 --- a/EIPS/eip-2327.md +++ b/EIPS/eip-2327.md @@ -5,7 +5,7 @@ author: Martin Lundfall martin.lundfall@protonmail.com discussions-to: https://ethereum-magicians.org/t/new-opcode-begindata/3727 status: Draft type: Standards Track -category Core +category: Core created: 2019-10-28 --- From 832f22990bdde635685348b38413623800e9a067 Mon Sep 17 00:00:00 2001 From: Martin Lundfall Date: Tue, 5 Nov 2019 14:23:08 +0100 Subject: [PATCH 5/5] eip-2327: Update formatting and clarify CODECOPY behaviour --- EIPS/eip-2327.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EIPS/eip-2327.md b/EIPS/eip-2327.md index a3a94ade74daf9..e18534f3ed4745 100644 --- a/EIPS/eip-2327.md +++ b/EIPS/eip-2327.md @@ -1,7 +1,7 @@ --- eip: 2327 title: BEGINDATA opcode -author: Martin Lundfall martin.lundfall@protonmail.com +author: Martin Lundfall (@MrChico) discussions-to: https://ethereum-magicians.org/t/new-opcode-begindata/3727 status: Draft type: Standards Track @@ -15,21 +15,21 @@ Introduces a new opcode `BEGINDATA`, which indicates that the remaining bytes of ## Abstract -It is common for smart contracts to efficiently store data directly in the contract bytecode. Examples include constant variables, compiler metadata and the contract runtime during the init phase. Currently, such data is not distinguished from normal bytecode and is still being analysed for JUMPDESTs by EVM interpreters. This EIP introduces a new opcode `BEGINDATA` at byte `0xb6`, which marks the remainding bytecode as data, indicating to EVM interpreters, static analysis tools and chain explorers that the remaining bytes do not represent opcodes. +It is common for smart contracts to efficiently store data directly in the contract bytecode. Examples include constant variables, compiler metadata and the contract runtime during the init phase. Currently, such data is not distinguished from normal bytecode and is still being analysed for `JUMPDEST`s by EVM interpreters. This EIP introduces a new opcode `BEGINDATA` at byte `0xb6`, which marks the remainding bytecode as data, indicating to EVM interpreters, static analysis tools and chain explorers that the remaining bytes do not represent opcodes. ## Motivation -The `BEGINDATA` opcode has been suggested before as part of the EIP `Subroutines and Static Jumps for the EVM` [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md) as a way to determine the position of jumptables in contract bytecode. It is here introduced in its own right in order to exclude data from the JUMPDEST analysis of contracts, making it impossible to jump to data. This makes it easier for static analysis tools to analyse contracts, allows disassemblers, chain explorers and debuggers to not display data as a mess of INVALID opcodes and may even provide a marginal improvement in performance. Additionally, it paves the way for suggestions such as [EIP 1712](https://github.com/ethereum/EIPs/pull/1712) to disallow unused opcodes, jumptables [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md) and speculative proposals to disallow for deployment of contracts with stack usage violations. +The `BEGINDATA` opcode has been suggested before as part of the EIP `Subroutines and Static Jumps for the EVM` [EIP-615](https://eips.ethereum.org/EIPS/eip-615) as a way to determine the position of jumptables in contract bytecode. It is here introduced in its own right in order to exclude data from the `JUMPDEST` analysis of contracts, making it impossible to jump to data. This makes it easier for static analysis tools to analyse contracts, allows disassemblers, chain explorers and debuggers to not display data as a mess of INVALID opcodes and may even provide a marginal improvement in performance. Additionally, it paves the way for suggestions such as [EIP 1712](https://github.com/ethereum/EIPs/pull/1712) to disallow unused opcodes, jumptables [EIP-615](https://eips.ethereum.org/EIPS/eip-615) and speculative proposals to disallow for deployment of contracts with stack usage violations. ## Specification -While computing the valid JUMPDESTs of a contract, halt analysis if `BEGINDATA` is encountered. A `JUMP` to a value higher than the `pc` value of `BEGINDATA` should throw with a `BAD_JUMP_DESTINATION` error. +While computing the valid `JUMPDEST`s of a contract, halt analysis if `BEGINDATA` is encountered. A `JUMP` to a value higher than the `PC` value of `BEGINDATA` should throw with a `BAD_JUMP_DESTINATION` error. Bytes past `BEGINDATA` remain accessible via `CODECOPY` and `EXTCODECOPY`. If `BEGINDATA` is encountered during contract execution, it has the same semantics as `STOP`. It uses 0 gas. ## Rationale -The byte `0xb6` was chosen to align with [EIP-615](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-615.md). -The choice to STOP if `BEGINDATA` is encountered is somewhat arbitrary. An alternative would be to `THROW`. +The byte `0xb6` was chosen to align with [EIP-615](https://eips.ethereum.org/EIPS/eip-615). +The choice to `STOP` if `BEGINDATA` is encountered is somewhat arbitrary. An alternative would be to be to abort the execution with an out-of-gas error. ## Backwards Compatibility @@ -38,7 +38,7 @@ The proposal will not change any existing contracts unless their current behavio ## Test Cases Test cases should include: -1) A contract which jumps to a destination `X`, where `X` has a pc value higher than the `BEGINDATA` opcode, and the byte at `X` is `0x5b`. This should fail with a `BAD_JUMPDEST`. +1) A contract which jumps to a destination `X`, where `X` has a pc value higher than the `BEGINDATA` opcode, and the byte at `X` is `0x5b`. This should fail with a `BAD_JUMP_DESTINATION` error. 2) A contract which encounters the `BEGINDATA` opcode (should stop executing the current call frame) ## Implementation