forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from NethermindEth/core/rip/7728-precompile-impl
[P2] Implements RIP-7728
- Loading branch information
Showing
12 changed files
with
207 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package vm | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type MockL1RPCClient struct{} | ||
|
||
func (m MockL1RPCClient) StoragesAt(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) ([]byte, error) { | ||
// testcase is in format "abab", this makes output lenght 2 bytes | ||
const mockedRespValueSize = 2 | ||
mockResp := make([]byte, mockedRespValueSize*len(keys)) | ||
for i := range keys { | ||
copy(mockResp[mockedRespValueSize*i:], common.Hex2Bytes("abab")) | ||
} | ||
|
||
return mockResp, nil | ||
} | ||
|
||
func TestPrecompiledL1SLOAD(t *testing.T) { | ||
mockL1RPCClient := MockL1RPCClient{} | ||
|
||
allPrecompiles[rollupL1SloadAddress] = &L1SLoad{} | ||
allPrecompiles.activateL1SLoad(mockL1RPCClient, func() *big.Int { return big1 }) | ||
|
||
testJson("l1sload", rollupL1SloadAddress.Hex(), t) | ||
testJsonFail("l1sload", rollupL1SloadAddress.Hex(), t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"Name": "L1SLOAD FAIL: input contains only address", | ||
"Input": "a83114A443dA1CecEFC50368531cACE9F37fCCcb", | ||
"ExpectedError": "L1SLOAD input too short", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
}, | ||
{ | ||
"Name": "L1SLOAD FAIL: input key not 32 bytes", | ||
"Input": "a83114A443dA1CecEFC50368531cACE9F37fCCcb112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7122", | ||
"ExpectedError": "L1SLOAD input is malformed", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
}, | ||
{ | ||
"Name": "L1SLOAD FAIL: input too long", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e8640112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7aa83114A443dA1CecEFC50368531cACE9F37fCCcb112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7122", | ||
"ExpectedError": "L1SLOAD input is malformed", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
} | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"Name": "L1SLOAD: 1 key", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e864", | ||
"Expected": "abab", | ||
"Gas": 4000, | ||
"NoBenchmark": true | ||
}, | ||
{ | ||
"Name": "L1SLOAD: 2 keys", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e8640112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a", | ||
"Expected": "abababab", | ||
"Gas": 6000, | ||
"NoBenchmark": true | ||
}, | ||
|
||
{ | ||
"Name": "L1SLOAD: 5 keys", | ||
"Input": "C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc22d2c7bb6fc06067df8b0223aec460d1ebb51febb9012bc2554141a4dca08e8640112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a112d016b65e9c617ad9ab60604f772a3620177bada4cdc773d9b6a982d3c2a7a", | ||
"Expected": "abababababababababab", | ||
"Gas": 12000, | ||
"NoBenchmark": true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tracers | ||
|
||
import "github.com/ethereum/go-ethereum/core/vm" | ||
|
||
func (b *testBackend) GetL1RpcClient() vm.L1RpcClient { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ethclient | ||
|
||
import ( | ||
"context" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/rpc" | ||
) | ||
|
||
// StoragesAt returns the values of keys in the contract storage of the given account. | ||
// The block number can be nil, in which case the value is taken from the latest known block. | ||
func (ec *Client) StoragesAt(ctx context.Context, account common.Address, keys []common.Hash, blockNumber *big.Int) ([]byte, error) { | ||
results := make([]hexutil.Bytes, len(keys)) | ||
reqs := make([]rpc.BatchElem, len(keys)) | ||
|
||
for i := range reqs { | ||
reqs[i] = rpc.BatchElem{ | ||
Method: "eth_getStorageAt", | ||
Args: []interface{}{account, keys[i], toBlockNumArg(blockNumber)}, | ||
Result: &results[i], | ||
} | ||
} | ||
if err := ec.c.BatchCallContext(ctx, reqs); err != nil { | ||
return nil, err | ||
} | ||
|
||
output := make([]byte, common.HashLength*len(keys)) | ||
for i := range reqs { | ||
if reqs[i].Error != nil { | ||
return nil, reqs[i].Error | ||
} | ||
copy(output[i*common.HashLength:], results[i]) | ||
} | ||
|
||
return output, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ethapi | ||
|
||
import "github.com/ethereum/go-ethereum/core/vm" | ||
|
||
func (b *testBackend) GetL1RpcClient() vm.L1RpcClient { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package ethapi | ||
|
||
import "github.com/ethereum/go-ethereum/core/vm" | ||
|
||
func (b *backendMock) GetL1RpcClient() vm.L1RpcClient { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package params | ||
|
||
const ( | ||
L1SLoadBaseGas uint64 = 2000 // Base price for L1Sload | ||
L1SLoadPerLoadGas uint64 = 2000 // Per-load price for loading one storage slot | ||
L1SLoadMaxNumStorageSlots = 5 // Max number of storage slots requested in L1Sload precompile | ||
L1SLoadRPCTimeoutInSec = 3 | ||
) |