Skip to content

Commit

Permalink
attempt at fixing replay + shadowfork
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Jul 31, 2024
1 parent 2eb89a9 commit c065295
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount,
for i := 0; i < 16 && i < len(balanceBytes); i++ {
basicData[utils.BasicDataBalanceOffset+i] = balanceBytes[len(balanceBytes)-1-i]
}
var cs [8]byte
binary.LittleEndian.PutUint64(cs[:], uint64(codeLen))
copy(basicData[utils.BasicDataCodeSizeOffset:], cs[:3])
// var cs [8]byte
// binary.LittleEndian.PutUint64(cs[:], uint64(codeLen))
// copy(basicData[utils.BasicDataCodeSizeOffset:], cs[:3])

values[utils.BasicDataLeafKey] = basicData[:]
values[utils.CodeHashLeafKey] = acc.CodeHash[:]
Expand Down Expand Up @@ -455,6 +455,22 @@ func (t *VerkleTrie) UpdateContractCode(addr common.Address, codeHash common.Has
}
values[groupOffset] = chunks[i : i+32]

// Reuse the calculated key to also update the code size.
if i == 0 {
// XXX add subfield update api
basicdata, err := t.root.Get(key, nil)
if err != nil {
return fmt.Errorf("UpdateContractCode (addr=%x) error getting basic data leaf: %w", addr[:], err)
}
if len(basicdata) == 0 {
return fmt.Errorf("UpdateContractCode (addr=%x) error getting non-zero basic data leaf: %w", addr[:], err)
}
cs := make([]byte, 32)
copy(cs[:], basicdata)
binary.BigEndian.PutUint32(cs[utils.BasicDataCodeSizeOffset-1:], uint32(len(code)))
values[utils.BasicDataLeafKey] = cs
}

if groupOffset == 255 || len(chunks)-i <= 32 {
err = t.UpdateStem(key[:31], values)

Expand Down

0 comments on commit c065295

Please sign in to comment.