Skip to content

Commit

Permalink
fix endianness issue + workaround for witness fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Feb 10, 2022
1 parent 5c064ab commit 0d057e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
11 changes: 9 additions & 2 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,19 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine
// building the proof. Ultimately, node
// resolution can be done with a prefetcher
// or from GetCommitmentsAlongPath.
kvs := statedb.Witness().KeyVals()
keys := statedb.Witness().Keys()
for _, key := range keys {
vtr.TryGet(key)
// XXX workaround - there is a problem in the witness creation
// so fix the witness creation as well.
v, err := vtr.TryGet(key)
if err != nil {
panic(err)
}
kvs[string(key)] = v
}
vtr.Hash()
p, k, err := vtr.ProveAndSerialize(keys, statedb.Witness().KeyVals())
p, k, err := vtr.ProveAndSerialize(keys, kvs)
block.SetVerkleProof(p, k)
if err != nil {
panic(err)
Expand Down
9 changes: 6 additions & 3 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,16 @@ func (t *VerkleTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
}
var nonce [32]byte
binary.LittleEndian.PutUint64(nonce[24:], acc.Nonce)
binary.LittleEndian.PutUint64(nonce[:], acc.Nonce)
if err = t.TryUpdate(utils.GetTreeKeyNonce(key), nonce[:]); err != nil {
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
}
var balance [32]byte
for i, b := range acc.Balance.Bytes() {
balance[31-i] = b
bbytes := acc.Balance.Bytes()
if len(bbytes) > 0 {
for i, b := range bbytes {
balance[len(bbytes)-i-1] = b
}
}
if err = t.TryUpdate(utils.GetTreeKeyBalance(key), balance[:]); err != nil {
return fmt.Errorf("updateStateObject (%x) error: %v", key, err)
Expand Down

0 comments on commit 0d057e0

Please sign in to comment.