Commit 8df3c50a authored by Matthew Slipper's avatar Matthew Slipper

op-node: Properly check storage proof

The storage proof was not being properly checked. This PR corrects the check, and adds unit/fuzz tests around the storage proof checks to prevent regressions.

Fixes CLI-3344
parent eb68d839
...@@ -3,7 +3,6 @@ package eth ...@@ -3,7 +3,6 @@ package eth
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
...@@ -52,12 +51,16 @@ func (res *AccountResult) Verify(stateRoot common.Hash) error { ...@@ -52,12 +51,16 @@ func (res *AccountResult) Verify(stateRoot common.Hash) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to verify storage value %d with key %s (path %x) in storage trie %s: %w", i, entry.Key, path, res.StorageHash, err) return fmt.Errorf("failed to verify storage value %d with key %s (path %x) in storage trie %s: %w", i, entry.Key, path, res.StorageHash, err)
} }
if !bytes.Equal(val, val) { comparison, err := rlp.EncodeToBytes(entry.Value.ToInt().Bytes())
if err != nil {
return fmt.Errorf("failed to encode storage value %d with key %s (path %x) in storage trie %s: %w", i, entry.Key, path, res.StorageHash, err)
}
if !bytes.Equal(val, comparison) {
return fmt.Errorf("value %d in storage proof does not match proven value at key %s (path %x)", i, entry.Key, path) return fmt.Errorf("value %d in storage proof does not match proven value at key %s (path %x)", i, entry.Key, path)
} }
} }
accountClaimed := []any{uint64(res.Nonce), (*big.Int)(res.Balance).Bytes(), res.StorageHash, res.CodeHash} accountClaimed := []any{uint64(res.Nonce), res.Balance.ToInt().Bytes(), res.StorageHash, res.CodeHash}
accountClaimedValue, err := rlp.EncodeToBytes(accountClaimed) accountClaimedValue, err := rlp.EncodeToBytes(accountClaimed)
if err != nil { if err != nil {
return fmt.Errorf("failed to encode account from retrieved values: %w", err) return fmt.Errorf("failed to encode account from retrieved values: %w", err)
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment