From d1d9a2e2a58f2144426252af75ef5fa51330d44c Mon Sep 17 00:00:00 2001 From: Dominic Letz Date: Tue, 29 Oct 2019 17:12:31 +0100 Subject: [PATCH 1/3] Added EIP-2330: SLOAD2 and ABI --- EIPS/eip-2330.md | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 EIPS/eip-2330.md diff --git a/EIPS/eip-2330.md b/EIPS/eip-2330.md new file mode 100644 index 00000000000000..74dca69de480bb --- /dev/null +++ b/EIPS/eip-2330.md @@ -0,0 +1,68 @@ +--- +eip: 2330 +title: SLOAD2 +author: Dominic Letz (@dominicletz) +discussions-to: https://ethereum-magicians.org/t/eip-2330-sload2-and-abi-for-lower-gas-cost-and-off-chain-apps/3733 +status: Draft +type: Standards Track +category: Core +created: 2019-10-29 +--- + + + +## Simple Summary + +A new `SLOAD2
` EVM opcode to read external contract storage data and corresponding allowing to build registry and token contracts that use less gas. + +## Abstract + +While any off-chain application can read all contract storage data of all contracts, this is not possible for deployed smart contracts themselves. These are bound to use contract calls for any interaction including reading data from other contracts. This EIP adds an EVM opcode to directly read external contract storage. + +## Motivation + +The gas cost when reading from registry style contract such as ERC-20s, ENS and other data contracts is very high, because they incur cross contract call cost, cost for ABI encoding, decoding and dispatching and finally loading the data. In many cases the underlying storage that is being queried is though just a simple mapping. In these cases a new SLOAD2 call directly accessing the mapping in storage could not only **reduce the gas cost** of the interaction more than 10x, but also it would make the gas cost **predictable** for the reading contract. + +## Specification + +**Proposal** +A new EVM instruction `SLOAD2 (0x5c)` that works like `SLOAD (0x54)` with the same gas cost but has an additional parameter representing the contract that is to be read from. + +``` +SLOAD (0x5c) +``` + +**Example** + +An example assuming further Solidity changes for illustration: + +```solidity +interface MemberList { + public fixed(@5) mapping(address => bool) members; +} +``` + +And a corresponding contract function that uses this member list. Similarly tokens or other registries could be implemented. + +```solidity +function membersOnly(address list, address member) { + MemberList ml = MemberList(list); + if (ml.members[client] == false) revert("Nonmember!"); +} +``` + +The call `ml.members[client]` here could let the Solidity compiler generate the normal map access logic but using the new `SLOAD2
` instructions to read from the `ml` contract storage instead of the local contract storage. + +## Backwards Compatibility +This change is fully backwards compatible since it adds a new instruction. + +## Test Cases + +Not started yet. + +## Implementation + +Not started yet. + +## Copyright +Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). From 9a37e96e675efd270682ab8fa04f14721cd1934c Mon Sep 17 00:00:00 2001 From: Dominic Letz Date: Fri, 1 Nov 2019 14:40:32 +0100 Subject: [PATCH 2/3] Renamed SLOAD2 to EXTSLOAD --- EIPS/eip-2330.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/EIPS/eip-2330.md b/EIPS/eip-2330.md index 74dca69de480bb..390242c9375670 100644 --- a/EIPS/eip-2330.md +++ b/EIPS/eip-2330.md @@ -1,8 +1,8 @@ --- eip: 2330 -title: SLOAD2 +title: EXTSLOAD author: Dominic Letz (@dominicletz) -discussions-to: https://ethereum-magicians.org/t/eip-2330-sload2-and-abi-for-lower-gas-cost-and-off-chain-apps/3733 +discussions-to: https://ethereum-magicians.org/t/eip-2330-extsload-and-abi-for-lower-gas-cost-and-off-chain-apps/3733 status: Draft type: Standards Track category: Core @@ -13,7 +13,7 @@ created: 2019-10-29 ## Simple Summary -A new `SLOAD2
` EVM opcode to read external contract storage data and corresponding allowing to build registry and token contracts that use less gas. +A new `EXTSLOAD ` EVM opcode to read external contract storage data and corresponding allowing to build registry and token contracts that use less gas. ## Abstract @@ -21,15 +21,15 @@ While any off-chain application can read all contract storage data of all contra ## Motivation -The gas cost when reading from registry style contract such as ERC-20s, ENS and other data contracts is very high, because they incur cross contract call cost, cost for ABI encoding, decoding and dispatching and finally loading the data. In many cases the underlying storage that is being queried is though just a simple mapping. In these cases a new SLOAD2 call directly accessing the mapping in storage could not only **reduce the gas cost** of the interaction more than 10x, but also it would make the gas cost **predictable** for the reading contract. +The gas cost when reading from registry style contract such as ERC-20s, ENS and other data contracts is very high, because they incur cross contract call cost, cost for ABI encoding, decoding and dispatching and finally loading the data. In many cases the underlying storage that is being queried is though just a simple mapping. In these cases a new `EXTSLOAD` call directly accessing the mapping in storage could not only **reduce the gas cost** of the interaction more than 10x, but also it would make the gas cost **predictable** for the reading contract. ## Specification **Proposal** -A new EVM instruction `SLOAD2 (0x5c)` that works like `SLOAD (0x54)` with the same gas cost but has an additional parameter representing the contract that is to be read from. +A new EVM instruction `EXTSLOAD (0x5c)` that works like `SLOAD (0x54)` with the gas cost of EXTCODE(700) + SLOAD(800) = 1500 and an additional parameter representing the contract that is to be read from. ``` -SLOAD (0x5c) +EXTSLOAD (0x5c) ``` **Example** @@ -51,7 +51,7 @@ function membersOnly(address list, address member) { } ``` -The call `ml.members[client]` here could let the Solidity compiler generate the normal map access logic but using the new `SLOAD2
` instructions to read from the `ml` contract storage instead of the local contract storage. +The call `ml.members[client]` here could let the Solidity compiler generate the normal map access logic but using the new `EXTSLOAD ` instructions to read from the `ml` contract storage instead of the local contract storage. ## Backwards Compatibility This change is fully backwards compatible since it adds a new instruction. From 343818c1206f5649bdbdfba12792e9abf3727533 Mon Sep 17 00:00:00 2001 From: Dominic Letz Date: Fri, 1 Nov 2019 16:00:21 +0100 Subject: [PATCH 3/3] Clarifying opcode specification --- EIPS/eip-2330.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/EIPS/eip-2330.md b/EIPS/eip-2330.md index 390242c9375670..db413b11db1884 100644 --- a/EIPS/eip-2330.md +++ b/EIPS/eip-2330.md @@ -1,6 +1,6 @@ --- eip: 2330 -title: EXTSLOAD +title: EXTSLOAD opcode author: Dominic Letz (@dominicletz) discussions-to: https://ethereum-magicians.org/t/eip-2330-extsload-and-abi-for-lower-gas-cost-and-off-chain-apps/3733 status: Draft @@ -26,15 +26,18 @@ The gas cost when reading from registry style contract such as ERC-20s, ENS and ## Specification **Proposal** -A new EVM instruction `EXTSLOAD (0x5c)` that works like `SLOAD (0x54)` with the gas cost of EXTCODE(700) + SLOAD(800) = 1500 and an additional parameter representing the contract that is to be read from. + +A new EVM instruction `EXTSLOAD (0x5c)` that works like `SLOAD (0x54)` but an additional parameter representing the contract that is to be read from. The gas cost of `EXTSLOAD` would be the sum of the [fee schedule G](https://ethereum.github.io/yellowpaper/paper.pdf) for G\[EXTCODE\](700) + G\[SLOAD\](800) = 1500 gas ``` -EXTSLOAD (0x5c) +EXTSLOAD (0x5c) ``` +The `EXTSLOAD` instruction pops 2 values from the stack, first `contract` a contract address and then second `slot` a storage address within `contract`. As result `EXTSLOAD` pushes on the stack the value from the contract storage of `contract` at the storage `slot` address or `0` in case the account `contract` does not exist. + **Example** -An example assuming further Solidity changes for illustration: +An example assuming [further Solidity changes](https://github.com/ethereum/solidity/issues/7593) for illustration: ```solidity interface MemberList {