-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into clabby/ctb/call-with-min-gas-fix
- Loading branch information
Showing
18 changed files
with
252 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@eth-optimism/sdk': patch | ||
--- | ||
|
||
Update the migrated withdrawal gas limit for non goerli networks |
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
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
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,50 @@ | ||
package kvstore | ||
|
||
import ( | ||
"encoding/binary" | ||
"encoding/json" | ||
|
||
"github.com/ethereum-optimism/optimism/op-program/host/config" | ||
"github.com/ethereum-optimism/optimism/op-program/preimage" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type LocalPreimageSource struct { | ||
config *config.Config | ||
} | ||
|
||
func NewLocalPreimageSource(config *config.Config) *LocalPreimageSource { | ||
return &LocalPreimageSource{config} | ||
} | ||
|
||
func localKey(num int64) common.Hash { | ||
return preimage.LocalIndexKey(num).PreimageKey() | ||
} | ||
|
||
var ( | ||
L1HeadKey = localKey(1) | ||
L2HeadKey = localKey(2) | ||
L2ClaimKey = localKey(3) | ||
L2ClaimBlockNumberKey = localKey(4) | ||
L2ChainConfigKey = localKey(5) | ||
RollupKey = localKey(6) | ||
) | ||
|
||
func (s *LocalPreimageSource) Get(key common.Hash) ([]byte, error) { | ||
switch key { | ||
case L1HeadKey: | ||
return s.config.L1Head.Bytes(), nil | ||
case L2HeadKey: | ||
return s.config.L2Head.Bytes(), nil | ||
case L2ClaimKey: | ||
return s.config.L2Claim.Bytes(), nil | ||
case L2ClaimBlockNumberKey: | ||
return binary.BigEndian.AppendUint64(nil, s.config.L2ClaimBlockNumber), nil | ||
case L2ChainConfigKey: | ||
return json.Marshal(s.config.L2ChainConfig) | ||
case RollupKey: | ||
return json.Marshal(s.config.Rollup) | ||
default: | ||
return nil, ErrNotFound | ||
} | ||
} |
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,56 @@ | ||
package kvstore | ||
|
||
import ( | ||
"encoding/binary" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimism/op-node/chaincfg" | ||
"github.com/ethereum-optimism/optimism/op-program/host/config" | ||
"github.com/ethereum-optimism/optimism/op-program/preimage" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/params" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLocalPreimageSource(t *testing.T) { | ||
cfg := &config.Config{ | ||
Rollup: &chaincfg.Goerli, | ||
L1Head: common.HexToHash("0x1111"), | ||
L2Head: common.HexToHash("0x2222"), | ||
L2Claim: common.HexToHash("0x3333"), | ||
L2ClaimBlockNumber: 1234, | ||
L2ChainConfig: params.GoerliChainConfig, | ||
} | ||
source := NewLocalPreimageSource(cfg) | ||
tests := []struct { | ||
name string | ||
key common.Hash | ||
expected []byte | ||
}{ | ||
{"L1Head", L1HeadKey, cfg.L1Head.Bytes()}, | ||
{"L2Head", L2HeadKey, cfg.L2Head.Bytes()}, | ||
{"L2Claim", L2ClaimKey, cfg.L2Claim.Bytes()}, | ||
{"L2ClaimBlockNumber", L2ClaimBlockNumberKey, binary.BigEndian.AppendUint64(nil, cfg.L2ClaimBlockNumber)}, | ||
{"Rollup", RollupKey, asJson(t, cfg.Rollup)}, | ||
{"ChainConfig", L2ChainConfigKey, asJson(t, cfg.L2ChainConfig)}, | ||
{"Unknown", preimage.LocalIndexKey(1000).PreimageKey(), nil}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, err := source.Get(test.key) | ||
if test.expected == nil { | ||
require.ErrorIs(t, err, ErrNotFound) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
require.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} | ||
|
||
func asJson(t *testing.T, v any) []byte { | ||
d, err := json.Marshal(v) | ||
require.NoError(t, err) | ||
return d | ||
} |
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,27 @@ | ||
package kvstore | ||
|
||
import ( | ||
"github.com/ethereum-optimism/optimism/op-program/preimage" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
type PreimageSource func(key common.Hash) ([]byte, error) | ||
|
||
type PreimageSourceSplitter struct { | ||
local PreimageSource | ||
global PreimageSource | ||
} | ||
|
||
func NewPreimageSourceSplitter(local PreimageSource, global PreimageSource) *PreimageSourceSplitter { | ||
return &PreimageSourceSplitter{ | ||
local: local, | ||
global: global, | ||
} | ||
} | ||
|
||
func (s *PreimageSourceSplitter) Get(key common.Hash) ([]byte, error) { | ||
if key[0] == byte(preimage.LocalKeyType) { | ||
return s.local(key) | ||
} | ||
return s.global(key) | ||
} |
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 kvstore | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimism/op-program/preimage" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPreimageSourceSplitter(t *testing.T) { | ||
localResult := []byte{1} | ||
globalResult := []byte{2} | ||
local := func(key common.Hash) ([]byte, error) { return localResult, nil } | ||
global := func(key common.Hash) ([]byte, error) { return globalResult, nil } | ||
splitter := NewPreimageSourceSplitter(local, global) | ||
|
||
tests := []struct { | ||
name string | ||
keyPrefix byte | ||
expected []byte | ||
}{ | ||
{"Local", byte(preimage.LocalKeyType), localResult}, | ||
{"Keccak", byte(preimage.Keccak256KeyType), globalResult}, | ||
{"Generic", byte(3), globalResult}, | ||
{"Reserved", byte(4), globalResult}, | ||
{"Application", byte(255), globalResult}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
key := common.Hash{0xff} | ||
key[0] = test.keyPrefix | ||
res, err := splitter.Get(key) | ||
require.NoError(t, err) | ||
require.Equal(t, test.expected, res) | ||
}) | ||
} | ||
} |
Oops, something went wrong.