diff --git a/trie/verkle.go b/trie/verkle.go index 120f19b9e779..b70ce89948cb 100644 --- a/trie/verkle.go +++ b/trie/verkle.go @@ -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[:] @@ -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)