mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 14:33:52 +00:00
feat(trace): add withdraw trie root (#217)
* init rollup/rcfg/config.go minor * update traces struct * init withdraw_trie.go * finish * fix `L2MessageQueueAddress` * refactor(rollup): add `UsingScroll` into `ChainConfig` (#218) * update comments * update comments
This commit is contained in:
parent
30f4f57f07
commit
8a78c736a5
5 changed files with 50 additions and 3 deletions
|
|
@ -31,6 +31,7 @@ type BlockTrace struct {
|
||||||
StorageTrace *StorageTrace `json:"storageTrace"`
|
StorageTrace *StorageTrace `json:"storageTrace"`
|
||||||
ExecutionResults []*ExecutionResult `json:"executionResults"`
|
ExecutionResults []*ExecutionResult `json:"executionResults"`
|
||||||
MPTWitness *json.RawMessage `json:"mptwitness,omitempty"`
|
MPTWitness *json.RawMessage `json:"mptwitness,omitempty"`
|
||||||
|
WithdrawTrieRoot common.Hash `json:"withdraw_trie_root,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// StorageTrace stores proofs of storage needed by storage circuit
|
// StorageTrace stores proofs of storage needed by storage circuit
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import (
|
||||||
"github.com/scroll-tech/go-ethereum/core/types"
|
"github.com/scroll-tech/go-ethereum/core/types"
|
||||||
"github.com/scroll-tech/go-ethereum/core/vm"
|
"github.com/scroll-tech/go-ethereum/core/vm"
|
||||||
"github.com/scroll-tech/go-ethereum/log"
|
"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/rpc"
|
||||||
"github.com/scroll-tech/go-ethereum/trie/zkproof"
|
"github.com/scroll-tech/go-ethereum/trie/zkproof"
|
||||||
)
|
)
|
||||||
|
|
@ -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
|
return blockTrace, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -258,16 +258,16 @@ var (
|
||||||
//
|
//
|
||||||
// This configuration is intentionally not using keyed fields to force anyone
|
// This configuration is intentionally not using keyed fields to force anyone
|
||||||
// adding flags to the config to also have to set these fields.
|
// 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
|
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
|
||||||
// and accepted by the Ethereum core developers into the Clique consensus.
|
// and accepted by the Ethereum core developers into the Clique consensus.
|
||||||
//
|
//
|
||||||
// This configuration is intentionally not using keyed fields to force anyone
|
// This configuration is intentionally not using keyed fields to force anyone
|
||||||
// adding flags to the config to also have to set these fields.
|
// 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))
|
TestRules = TestChainConfig.Rules(new(big.Int))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -370,6 +370,10 @@ type ChainConfig struct {
|
||||||
|
|
||||||
// Scroll genesis extension: Maximum number of transactions per block [optional]
|
// Scroll genesis extension: Maximum number of transactions per block [optional]
|
||||||
MaxTxPerBlock *int `json:"maxTxPerBlock,omitempty"`
|
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.
|
// EthashConfig is the consensus engine configs for proof-of-work based sealing.
|
||||||
|
|
|
||||||
18
rollup/rcfg/config.go
Normal file
18
rollup/rcfg/config.go
Normal file
|
|
@ -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
rollup/withdrawtrie/withdraw_trie.go
Normal file
18
rollup/withdrawtrie/withdraw_trie.go
Normal file
|
|
@ -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)
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue