Skip to content

Commit

Permalink
Merge branch 'zkevm' into refactor-stage-batches
Browse files Browse the repository at this point in the history
  • Loading branch information
V-Staykov authored Oct 3, 2024
2 parents 19513a6 + 0948e33 commit b50e101
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions chain/chain_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type Config struct {
ForkID12BananaBlock *big.Int `json:"forkID12BananaBlock,omitempty"`

AllowFreeTransactions bool `json:"allowFreeTransactions,omitempty"`
ZkDefaultGasPrice uint64 `json:"zkDefaultGasFee,omitempty"`
}

func (c *Config) String() string {
Expand Down
3 changes: 2 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,8 @@ var (
DefaultGasPrice = cli.Uint64Flag{
Name: "zkevm.default-gas-price",
Usage: "Set the default/min gas price",
Value: 0,
// 0.01 gwei
Value: 10000000,
}
MaxGasPrice = cli.Uint64Flag{
Name: "zkevm.max-gas-price",
Expand Down
2 changes: 1 addition & 1 deletion consensus/misc/eip1559.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func VerifyEip1559Header(config *chain.Config, parent, header *types.Header) err
func CalcBaseFee(config *chain.Config, parent *types.Header) *big.Int {
// If the current block is the first EIP-1559 block, return the InitialBaseFee.
if !config.IsLondon(parent.Number.Uint64()) {
return new(big.Int).SetUint64(params.InitialBaseFee)
return new(big.Int).SetUint64(config.ZkDefaultGasPrice)
}

var (
Expand Down
2 changes: 2 additions & 0 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func copyConfig(original *chain.Config) *chain.Config {
func config() *chain.Config {
config := copyConfig(params.TestChainConfig)
config.LondonBlock = big.NewInt(5)
// setting the default expected fee for tests
config.ZkDefaultGasPrice = params.InitialBaseFee
return config
}

Expand Down
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
cfg := backend.config

backend.chainConfig.AllowFreeTransactions = cfg.AllowFreeTransactions
backend.chainConfig.ZkDefaultGasPrice = cfg.DefaultGasPrice
l1Urls := strings.Split(cfg.L1RpcUrl, ",")

if cfg.Zk.L1CacheEnabled {
Expand Down
6 changes: 6 additions & 0 deletions zk/contracts/l1_abi.go

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions zk/l1_data/l1_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,32 @@ func DecodeL1BatchData(txData []byte, daUrl string) ([][]byte, common.Address, u
return nil, common.Address{}, 0, fmt.Errorf("expected position 1 in the l1 call data to be the limit timestamp")
}
limitTimstamp = ts
case contracts.SequenceBatchesBanana:
cb, ok := data[4].(common.Address)
if !ok {
return nil, common.Address{}, 0, fmt.Errorf("expected position 4 in the l1 call data to be address")
}
coinbase = cb
ts, ok := data[2].(uint64)
if !ok {
return nil, common.Address{}, 0, fmt.Errorf("expected position 1 in the l1 call data to be the limit timestamp")
}
limitTimstamp = ts
case contracts.SequenceBatchesValidiumBanana:
if daUrl == "" {
return nil, common.Address{}, 0, fmt.Errorf("data availability url is required for validium")
}
isValidium = true
cb, ok := data[4].(common.Address)
if !ok {
return nil, common.Address{}, 0, fmt.Errorf("expected position 4 in the l1 call data to be address")
}
coinbase = cb
ts, ok := data[2].(uint64)
if !ok {
return nil, common.Address{}, 0, fmt.Errorf("expected position 1 in the l1 call data to be the limit timestamp")
}
limitTimstamp = ts
default:
return nil, common.Address{}, 0, fmt.Errorf("unknown l1 call data")
}
Expand Down
48 changes: 48 additions & 0 deletions zk/l1_data/l1_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ func Test_DecodeL1BatchData(t *testing.T) {
}
}

func Test_DecodeL1MultiBatchDataBanana(t *testing.T) {
testData := "0xb910e0f900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000066fae3d43c6b68527a14b86763ec2b181d3598cdc7250d1dde0887492779a8dd0d7f12d50000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002c0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b00000006000000000b00000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b00000006000000000b00000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b00000006000000000b00000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b00000006000000000b00000006000000000000000000000000000000000000"
txData := common.FromHex(testData)

transactions, _, _, err := DecodeL1BatchData(txData, "")
if err != nil {
t.Fatal(err)
}
if len(transactions) != 4 {
t.Errorf("expected 4 transaction but found %v", len(transactions))
}
}

func Test_DecodeL1BatchValidiumDataNoDAUrl(t *testing.T) {
testData := "0xdb5b0ed700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006660bbff000000000000000000000000000000000000000000000000000000000000001b0000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed00000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003dd6adb9b5339c8211dc51e7a58a554ed96cf79e3ee7fc2584989fc59f9498a8500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082bf94a92db64c7577bee972b708e40197417a4cbff9cd222ea4a5e0dc059f3e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034bd4848d9132849924ed6fe5af836533213534badcfb3de4ba00654943d7c3d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005513b771ebf43620a7b45c4f6e7e766339c82a475187494122f1390509947a4854643ed73c45dff20dcfe99ba777e5fd8271abfab69e9b96bb5fd9dc242373bec51b5951f5b2604c9b42e478d5e2b2437f44073ef9a60000000000000000000000"
txData := common.FromHex(testData)
Expand All @@ -37,6 +50,41 @@ func Test_DecodeL1BatchValidiumDataNoDAUrl(t *testing.T) {
}
}

func Test_DecodeL1BatchValidiumDataBanana(t *testing.T) {
testData := "0x165e8a8d00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000066fae9a308dfbf8c1ca0c355b92a5cfef496d96d2bcfa77ebcb3d20202bf1640f1b440ae0000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed0000000000000000000000000000000000000000000000000000000000000260000000000000000000000000000000000000000000000000000000000000000314df0077a11ccf22bd14d1ec3e209ba5d8e065ce73556fdc8fb9c19b83af4ec3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dd6adb9b5339c8211dc51e7a58a554ed96cf79e3ee7fc2584989fc59f9498a8500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014df0077a11ccf22bd14d1ec3e209ba5d8e065ce73556fdc8fb9c19b83af4ec3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005579a845d67ad87cf4a4509825fd3ecbb4eba6170dd6ef7926966c2da40d6607c866d66591fbd68ae874e7b2c8daf6f40c4b6bc5d0e6379fbb8e297e4231ced19b1b5951f5b2604c9b42e478d5e2b2437f44073ef9a60000000000000000000000"
txData := common.FromHex(testData)

svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var res types.Request
require.NoError(t, json.NewDecoder(r.Body).Decode(&res))
require.Equal(t, "sync_getOffChainData", res.Method)

var params []common.Hash
require.NoError(t, json.Unmarshal(res.Params, &params))

if params[0] == common.HexToHash("0xdd6adb9b5339c8211dc51e7a58a554ed96cf79e3ee7fc2584989fc59f9498a85") {
_, err := fmt.Fprint(w, `{"result":"0x0b00000006000000000b0000000600000000"}`)
require.NoError(t, err)
} else if params[0] == common.HexToHash("0x14df0077a11ccf22bd14d1ec3e209ba5d8e065ce73556fdc8fb9c19b83af4ec3") {
_, err := fmt.Fprint(w, `{"result":"0x0b00000006000000000b00000006000000000b0000000600000000"}`)
require.NoError(t, err)
} else {
_, err := fmt.Fprint(w, `{"error":{"code":123,"message":"test error"}}`)
require.NoError(t, err)
}
}))
defer svr.Close()

transactions, _, _, err := DecodeL1BatchData(txData, svr.URL)
if err != nil {
t.Fatal(err)
}

if len(transactions) != 3 {
t.Errorf("expected 3 transactions but found %v", len(transactions))
}
}

func Test_DecodeL1BatchValidiumData(t *testing.T) {
testData := "0xdb5b0ed700000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000006660bbff000000000000000000000000000000000000000000000000000000000000001b0000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed00000000000000000000000000000000000000000000000000000000000002400000000000000000000000000000000000000000000000000000000000000003dd6adb9b5339c8211dc51e7a58a554ed96cf79e3ee7fc2584989fc59f9498a8500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082bf94a92db64c7577bee972b708e40197417a4cbff9cd222ea4a5e0dc059f3e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034bd4848d9132849924ed6fe5af836533213534badcfb3de4ba00654943d7c3d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005513b771ebf43620a7b45c4f6e7e766339c82a475187494122f1390509947a4854643ed73c45dff20dcfe99ba777e5fd8271abfab69e9b96bb5fd9dc242373bec51b5951f5b2604c9b42e478d5e2b2437f44073ef9a60000000000000000000000"
txData := common.FromHex(testData)
Expand Down
8 changes: 5 additions & 3 deletions zk/tests/unwinds/unwind.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dataPath="./datadir"
firstStop=11204
stopBlock=11315
unwindBatch=70
firstTimeout=120s
secondTimeout=60s

rm -rf "$dataPath/rpc-datadir"
rm -rf "$dataPath/phase1-dump1"
Expand All @@ -31,7 +33,7 @@ timeout 300s go run ./zk/debug_tools/datastream-host --file="$(pwd)/zk/tests/unw
sleep 5

# run erigon for a while to sync to the unwind point to capture the dump
timeout 40s ./build/bin/cdk-erigon \
timeout $firstTimeout ./build/bin/cdk-erigon \
--datadir="$dataPath/rpc-datadir" \
--config=./dynamic-integration8.yaml \
--zkevm.sync-limit=${firstStop}
Expand All @@ -40,7 +42,7 @@ timeout 40s ./build/bin/cdk-erigon \
go run ./cmd/hack --action=dumpAll --chaindata="$dataPath/rpc-datadir/chaindata" --output="$dataPath/phase1-dump1"

# now run to the final stop block
timeout 15s ./build/bin/cdk-erigon \
timeout $secondTimeout ./build/bin/cdk-erigon \
--datadir="$dataPath/rpc-datadir" \
--config=./dynamic-integration8.yaml \
--zkevm.sync-limit=${stopBlock}
Expand All @@ -59,7 +61,7 @@ go run ./cmd/integration state_stages_zkevm \
go run ./cmd/hack --action=dumpAll --chaindata="$dataPath/rpc-datadir/chaindata" --output="$dataPath/phase1-dump2"

# now sync again
timeout 15s ./build/bin/cdk-erigon \
timeout $secondTimeout ./build/bin/cdk-erigon \
--datadir="$dataPath/rpc-datadir" \
--config=./dynamic-integration8.yaml \
--zkevm.sync-limit=${stopBlock}
Expand Down

0 comments on commit b50e101

Please sign in to comment.