mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
[FIX]: zkproof writer handle reading non-existed address (#197)
zkproof writer: fix issue in reading unexist address
This commit is contained in:
parent
5ca70bf3a2
commit
81aafb09f3
1 changed files with 13 additions and 4 deletions
|
|
@ -406,13 +406,12 @@ func (w *zktrieProofWriter) traceAccountUpdate(addr common.Address, updateAccDat
|
|||
return nil, fmt.Errorf("update zktrie account state fail: %s", err)
|
||||
}
|
||||
w.tracingAccounts[addr] = accData
|
||||
} else {
|
||||
} else if accDataBefore != nil {
|
||||
if err := w.tracingZktrie.TryDelete(addr.Bytes32()); err != nil {
|
||||
return nil, fmt.Errorf("delete zktrie account state fail: %s", err)
|
||||
}
|
||||
w.tracingAccounts[addr] = nil
|
||||
|
||||
}
|
||||
} // notice if both before/after is nil, we do not touch zktrie
|
||||
|
||||
proof = proofList{}
|
||||
if err := w.tracingZktrie.Prove(s_key.Bytes(), 0, &proof); err != nil {
|
||||
|
|
@ -459,6 +458,7 @@ func (w *zktrieProofWriter) traceStorageUpdate(addr common.Address, key, value [
|
|||
storeKey := zkt.NewByte32FromBytesPaddingZero(common.BytesToHash(key).Bytes())
|
||||
storeValueBefore := trie.Get(storeKey[:])
|
||||
storeValue := zkt.NewByte32FromBytes(value)
|
||||
valZero := zkt.Byte32{}
|
||||
|
||||
if storeValueBefore != nil && !bytes.Equal(storeValueBefore[:], common.Hash{}.Bytes()) {
|
||||
stateUpdate[0] = &StateStorage{
|
||||
|
|
@ -503,7 +503,11 @@ func (w *zktrieProofWriter) traceStorageUpdate(addr common.Address, key, value [
|
|||
out, err := w.traceAccountUpdate(addr,
|
||||
func(acc *types.StateAccount) *types.StateAccount {
|
||||
if acc == nil {
|
||||
panic("unexpected")
|
||||
// in case we read an unexist account
|
||||
if !bytes.Equal(valZero.Bytes(), value) {
|
||||
panic(fmt.Errorf("write to an unexist account [%s] which is not allowed", addr))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//sanity check
|
||||
|
|
@ -533,6 +537,11 @@ func (w *zktrieProofWriter) traceStorageUpdate(addr common.Address, key, value [
|
|||
} else {
|
||||
out.StateKey = zkt.NewHashFromBigInt(h)[:]
|
||||
}
|
||||
stateUpdate[1] = &StateStorage{
|
||||
Key: storeKey.Bytes(),
|
||||
Value: valZero.Bytes(),
|
||||
}
|
||||
stateUpdate[0] = stateUpdate[1]
|
||||
}
|
||||
|
||||
out.StatePath = statePath
|
||||
|
|
|
|||
Loading…
Reference in a new issue