Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Oct 24, 2024
1 parent 0406d61 commit 5fe94aa
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 24 deletions.
51 changes: 27 additions & 24 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
return h
}
var (
statedb = MakePreState(rawdb.NewMemoryDatabase(), chainConfig, pre, chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp))
vtrpre *trie.VerkleTrie
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
gaspool = new(core.GasPool)
blockHash = common.Hash{0x13, 0x37}
rejectedTxs []*rejectedTx
includedTxs types.Transactions
gasUsed = uint64(0)
receipts = make(types.Receipts, 0)
txIndex = 0
parentRoot, statedb = MakePreState(rawdb.NewMemoryDatabase(), chainConfig, pre, chainConfig.IsVerkle(big.NewInt(int64(pre.Env.Number)), pre.Env.Timestamp))
vtrpre *trie.VerkleTrie
signer = types.MakeSigner(chainConfig, new(big.Int).SetUint64(pre.Env.Number), pre.Env.Timestamp)
gaspool = new(core.GasPool)
blockHash = common.Hash{0x13, 0x37}
rejectedTxs []*rejectedTx
includedTxs types.Transactions
gasUsed = uint64(0)
receipts = make(types.Receipts, 0)
txIndex = 0
)
gaspool.AddGas(pre.Env.GasLimit)
vmContext := vm.BlockContext{
Expand Down Expand Up @@ -392,7 +392,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee),
VerkleProof: vktProof,
StateDiff: vktStateDiff,
ParentRoot: pre.Env.BlockHashes[math.HexOrDecimal64(pre.Env.Number-1)],
ParentRoot: parentRoot,
}
if pre.Env.Withdrawals != nil {
h := types.DeriveSha(types.Withdrawals(pre.Env.Withdrawals), trie.NewStackTrie(nil))
Expand Down Expand Up @@ -427,7 +427,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
return statedb, execRs, nil
}

func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prestate, verkle bool) *state.StateDB {
func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prestate, verkle bool) (common.Hash, *state.StateDB) {
// Start with generating the MPT DB, which should be empty if it's post-verkle transition
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true, Verkle: false})

Expand All @@ -453,9 +453,12 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
codeHash := crypto.Keccak256Hash(acc.Code)
rawdb.WriteCode(codeWriter, codeHash, acc.Code)
}
statedb.Commit(0, false)
root, err := statedb.Commit(0, false)
if err != nil {
panic(err)
}

return statedb
return root, statedb
}

// MPT pre is the same as the pre state for first conversion block
Expand All @@ -470,7 +473,7 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest

state.NoBanner()
// Commit db an create a snapshot from it.
mptRoot, err := statedb.Commit(0, false)
root, err := statedb.Commit(0, false)
if err != nil {
panic(err)
}
Expand All @@ -480,19 +483,19 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
// If the current tree is a VerkleTrie, it means the state conversion has ended.
// We don't need to continue with conversion setups and can return early.
if _, ok := statedb.GetTrie().(*trie.VerkleTrie); ok {
return statedb
return root, statedb
}

rawdb.WritePreimages(sdb.DiskDB(), statedb.Preimages())
sdb.TrieDB().WritePreimages()
snaps, err := snapshot.New(snapshot.Config{AsyncBuild: false, CacheSize: 10}, sdb.DiskDB(), sdb.TrieDB(), mptRoot)
snaps, err := snapshot.New(snapshot.Config{AsyncBuild: false, CacheSize: 10}, sdb.DiskDB(), sdb.TrieDB(), root)
if err != nil {
panic(err)
}
if snaps == nil {
panic("snapshot is nil")
}
snaps.Cap(mptRoot, 0)
snaps.Cap(root, 0)

// reuse the backend db so that the snapshot can be enumerated

Expand All @@ -501,7 +504,7 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
if pre.Env.Started != nil {
log.Info("non-nil started", "started", *pre.Env.Started)
}
sdb.InitTransitionStatus(pre.Env.Started != nil && *pre.Env.Started, pre.Env.Ended != nil && *pre.Env.Ended, mptRoot)
sdb.InitTransitionStatus(pre.Env.Started != nil && *pre.Env.Started, pre.Env.Ended != nil && *pre.Env.Ended, root)
log.Info("loading current account address, if available", "available", pre.Env.CurrentAccountAddress != nil)
if pre.Env.CurrentAccountAddress != nil {
log.Info("loading current account address", "address", *pre.Env.CurrentAccountAddress)
Expand All @@ -515,9 +518,9 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
}

// start the conversion on the first block
log.Info("starting verkle transition?", "in transition", sdb.InTransition(), "transitioned", sdb.Transitioned(), "mpt root", mptRoot)
log.Info("starting verkle transition?", "in transition", sdb.InTransition(), "transitioned", sdb.Transitioned(), "mpt root", root)
if !sdb.InTransition() && !sdb.Transitioned() {
sdb.StartVerkleTransition(mptRoot, mptRoot, chainConfig, chainConfig.VerkleTime, mptRoot)
sdb.StartVerkleTransition(root, root, chainConfig, chainConfig.VerkleTime, root)
}

// create the state database without the snapshot, so that it's not overwritten
Expand Down Expand Up @@ -549,7 +552,7 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
vtr.UpdateStem(k.Bytes(), values)
}

root, _ := statedb.Commit(0, false)
root, _ = statedb.Commit(0, false)

// recreate the verkle db with the tree root, but this time with the mpt snapshot,
// so that the conversion can proceed.
Expand All @@ -558,7 +561,7 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
panic(err)
}
} else {
statedb, err = state.New(mptRoot, sdb, nil)
statedb, err = state.New(root, sdb, nil)
if err != nil {
panic(err)
}
Expand All @@ -567,7 +570,7 @@ func MakePreState(db ethdb.Database, chainConfig *params.ChainConfig, pre *Prest
if statedb.Database().InTransition() || statedb.Database().Transitioned() {
log.Info("at end of makestate", "in transition", statedb.Database().InTransition(), "during", statedb.Database().Transitioned(), "account hash", statedb.Database().GetCurrentAccountHash())
}
return statedb
return root, statedb
}

func rlpHash(x interface{}) (h common.Hash) {
Expand Down
113 changes: 113 additions & 0 deletions cmd/evm/witness.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
{
"Proof": {
"otherStems": [],
"depthExtensionPresent": "0x0a0a080a0a",
"commitmentsByPath": [
"0x360bcc4c15a10f6f058d1d07e13e9a271da3da0cd69026d5a9ab25e1c0a5d697",
"0x324e7b7405bbfae46866bad5c94ac2983093b86f85035fe5984ec40a1b5e5ce3",
"0x61506c1cc4f27c9231a546a4b0d249d5f3ba4ba9e63c5ebb84087665eb396e95",
"0x4909fc1889e10819cda41706a26373145c4e4575d68b96569af12db69040b6e1",
"0x24ea14e5046970eb068cf4959e7ffd145e77ed3842c9b5bcd099c8564273d60a",
"0x6d2dafbbc758a4b1d9d88af18d05297e8c6b3765f93eb216e3be8ad1a8f2629d",
"0x2b0e7b7dfc4c48af96e96f0951302cbcc3623d5d8d592396539b80d36ffdef9d",
"0x3de3f4e9557c30860a15d4afc3e98dc2d2afebee91375524b46bdbe1c7fba86c",
"0x4ff986311ca51efc05bdde6288600e94ba55567b916e43adccc7c46ee7187dfb"
],
"d": "0x0e359c50fc0782a3f873eb864e227517127caf1078757fb60eeae53f6fc311f6",
"ipaProof": {
"cl": [
"0x6bf549d10a2877e38ca9f1f74f3792e7ba170a345d0f537747f9e9cee017e30b",
"0x5bccb34f1cd1441a8c91c51c1ef78c10d5b022d8a5662cbf9b4eb78d76129ea3",
"0x081c7bad7e036ce53e5019404bf7af1bb70fbcf61a3b292d74662d2d422b60c9",
"0x57107b42575e5e764537d3a19e8da29cd7f63749629864eb39a136687d2c566b",
"0x2bef5468fbede840921688902e8b303706d77fa592c290ff821e7081b019f99f",
"0x24349d4d2a60deed962029748224a41ecc755d5ee1901e6c0c32fb3e928b5c17",
"0x5931496b893fa568eb78977369f17cd0561584b9fe9e5591204b94a19302f11f",
"0x6cd72480c5485b74a0a608c275ad81e4a5e8f5e7b9696e798e1466f87bbcd32f"
],
"cr": [
"0x589d37a499e72e454feb0a5aca2875fd74d23bfe5e452827f1fca33643193c90",
"0x0039e7d08af2372e00e9428bd495bec4d2fcb336c951d8a6d05535b838e2aa91",
"0x2136974178d7df3f67e07ff54a43e2cc4b56a4311fc5396c69d783009141398e",
"0x4c84edeff22cff0d18ddf6e7d2a1b2ee38f612f2b12c1a730873ad465b309270",
"0x0319071230d46dd24f1d9b92bf606983b07e1ccbf012193f66b49ba07c7e0156",
"0x05a568daf779880d3f06f05521b9408d3160c87b2d54d0c514b7af7b5d1ae59f",
"0x5d94271522bd352fd2da9e8995087b14b7fec7c044f66e00e6a405ae864db5bb",
"0x510ec469c4cc35a88bea434bf4943dfcee60fb6bff0cfa837566468393dcaeb6"
],
"finalEvaluation": "0x002812ef6422bc0c0d112a76c51f5f8d2f63dc3843845a7e5db9ceb2953b74b8"
}
},
"Diff": [
{
"stem": "0x0365b079a274a1808d56484ce5bd97914629907d75767f51439102e22cd50d",
"suffixDiffs": [
{
"suffix": 0,
"currentValue": "0x00000000000000000000000000000000000000000000003635c9adc5dea00000",
"newValue": "0x00000000000000000000000000000001000000000000003635c9adc5de9bae6a"
},
{
"suffix": 1,
"currentValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"newValue": null
}
]
},
{
"stem": "0x5b5fdfedd6a0e932da408ac7d772a36513d1eee9b9926e52620c43a433aad7",
"suffixDiffs": [
{
"suffix": 64,
"currentValue": null,
"newValue": "0x7179c5e2d57695a9e8850337251f3c81829daf3c1c2b8818f26e9c9956c885b2"
}
]
},
{
"stem": "0x914ec5f0e0c27fe094862fbd89a6abe684939af6940434d8bf218cedb2d624",
"suffixDiffs": [
{
"suffix": 0,
"currentValue": null,
"newValue": "0x0000000000000000000000000000000000000000000000000000000000014bad"
},
{
"suffix": 1,
"currentValue": null,
"newValue": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
}
]
},
{
"stem": "0x9bcc6e55c098e22bfe2feee3cefcd2abab05249f3fd93a77cb65eeee3e0398",
"suffixDiffs": [
{
"suffix": 0,
"currentValue": "0x00000000000000000000000000000000000000000000000000000000000000ff",
"newValue": null
}
]
},
{
"stem": "0xecb505156708480caf702cd85124f67f3ed78ae4bc890a6dcb62574ba9a90c",
"suffixDiffs": [
{
"suffix": 0,
"currentValue": "0x0000000000000016000000000000000000000000000000000000000000000064",
"newValue": null
},
{
"suffix": 1,
"currentValue": "0x033ec231123b4118647747870c5f579cce50bc1e816e1e32b0341277600d2730",
"newValue": null
},
{
"suffix": 128,
"currentValue": "0x0073d94f5374fce5edbc8e2a8697c15331677e6ebf0cff000000000000000000",
"newValue": null
}
]
}
]
}

0 comments on commit 5fe94aa

Please sign in to comment.