Skip to content

Commit

Permalink
feat(trace): add withdraw trie root (ethereum#217)
Browse files Browse the repository at this point in the history
* init rollup/rcfg/config.go

minor

* update traces struct

* init withdraw_trie.go

* finish

* fix `L2MessageQueueAddress`

* refactor(rollup): add `UsingScroll` into `ChainConfig` (ethereum#218)

* update comments

* update comments
  • Loading branch information
0xmountaintop authored Feb 16, 2023
1 parent 30f4f57 commit 8a78c73
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions core/types/l2trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type BlockTrace struct {
StorageTrace *StorageTrace `json:"storageTrace"`
ExecutionResults []*ExecutionResult `json:"executionResults"`
MPTWitness *json.RawMessage `json:"mptwitness,omitempty"`
WithdrawTrieRoot common.Hash `json:"withdraw_trie_root,omitempty"`
}

// StorageTrace stores proofs of storage needed by storage circuit
Expand Down
6 changes: 6 additions & 0 deletions eth/tracers/api_blocktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
"github.com/scroll-tech/go-ethereum/rollup/withdrawtrie"
"github.com/scroll-tech/go-ethereum/rpc"
"github.com/scroll-tech/go-ethereum/trie/zkproof"
)
Expand Down Expand Up @@ -384,5 +386,9 @@ func (api *API) fillBlockTrace(env *traceEnv, block *types.Block) (*types.BlockT
}
}

if api.backend.ChainConfig().UsingScroll {
blockTrace.WithdrawTrieRoot = withdrawtrie.ReadWTRSlot(rcfg.L2MessageQueueAddress, env.state)
}

return blockTrace, nil
}
10 changes: 7 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,16 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, nil, true, true, nil}
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, nil, true, true, nil, true}

// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus.
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, false, nil, true, true, nil}
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, false, nil, true, true, nil, true}

TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, &common.Address{123}, true, true, nil}
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, new(EthashConfig), nil, false, &common.Address{123}, true, true, nil, true}
TestRules = TestChainConfig.Rules(new(big.Int))
)

Expand Down Expand Up @@ -370,6 +370,10 @@ type ChainConfig struct {

// Scroll genesis extension: Maximum number of transactions per block [optional]
MaxTxPerBlock *int `json:"maxTxPerBlock,omitempty"`

// Scroll genesis extension: enable scroll rollup-related traces & state transition
// TODO: merge with these config: Zktrie, FeeVaultAddress, EnableEIP2718, EnableEIP1559 & MaxTxPerBlock
UsingScroll bool `json:"usingScroll,omitempty"`
}

// EthashConfig is the consensus engine configs for proof-of-work based sealing.
Expand Down
18 changes: 18 additions & 0 deletions rollup/rcfg/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package rcfg

import (
"math/big"

"github.com/scroll-tech/go-ethereum/common"
)

// TODO:
// verify in consensus layer when decentralizing sequencer

var (
// L2MessageQueueAddress is the address of the L2MessageQueue
// predeploy
// see contracts/src/L2/predeploys/L2MessageQueue.sol
L2MessageQueueAddress = common.HexToAddress("0x5300000000000000000000000000000000000000")
WithdrawTrieRootSlot = common.BigToHash(big.NewInt(0))
)
18 changes: 18 additions & 0 deletions rollup/withdrawtrie/withdraw_trie.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package withdrawtrie

import (
"github.com/scroll-tech/go-ethereum/common"
"github.com/scroll-tech/go-ethereum/rollup/rcfg"
)

// StateDB represents the StateDB interface
// required to get withdraw trie root
type StateDB interface {
GetState(common.Address, common.Hash) common.Hash
}

// ReadWTRSlot reads WithdrawTrieRoot slot in L2MessageQueue predeploy, i.e., `messageRoot`
// in contracts/src/libraries/common/AppendOnlyMerkleTree.sol
func ReadWTRSlot(addr common.Address, state StateDB) common.Hash {
return state.GetState(addr, rcfg.WithdrawTrieRootSlot)
}

0 comments on commit 8a78c73

Please sign in to comment.