Upgrade go-verkle to its IPA version (#24)
This commit is contained in:
		@@ -1602,7 +1602,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals, setHead bool)
 | 
			
		||||
			receipts, logs, _, usedGas, err = bc.processor.Process(block, statedb, bc.vmConfig)
 | 
			
		||||
		} else {
 | 
			
		||||
			var leaves map[common.Hash]common.Hash
 | 
			
		||||
			_, _, _, leaves, err = trie.DeserializeAndVerifyVerkleProof(block.Header().VerkleProof)
 | 
			
		||||
			leaves, err = trie.DeserializeAndVerifyVerkleProof(block.Header().VerkleProof)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return it.index, err
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,7 +27,6 @@ import (
 | 
			
		||||
	"github.com/ethereum/go-ethereum/rlp"
 | 
			
		||||
	"github.com/ethereum/go-ethereum/trie/utils"
 | 
			
		||||
	"github.com/gballet/go-verkle"
 | 
			
		||||
	"github.com/protolambda/go-kzg/bls"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// VerkleTrie is a wrapper around VerkleNode that implements the trie.Trie
 | 
			
		||||
@@ -105,11 +104,11 @@ func (trie *VerkleTrie) TryDelete(key []byte) error {
 | 
			
		||||
func (trie *VerkleTrie) Hash() common.Hash {
 | 
			
		||||
	// TODO cache this value
 | 
			
		||||
	rootC := trie.root.ComputeCommitment()
 | 
			
		||||
	return bls.FrTo32(rootC)
 | 
			
		||||
	return rootC.Bytes()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func nodeToDBKey(n verkle.VerkleNode) []byte {
 | 
			
		||||
	ret := bls.FrTo32(n.ComputeCommitment())
 | 
			
		||||
	ret := n.ComputeCommitment().Bytes()
 | 
			
		||||
	return ret[:]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -172,23 +171,19 @@ type KeyValuePair struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type verkleproof struct {
 | 
			
		||||
	D *bls.G1Point
 | 
			
		||||
	Y *bls.Fr
 | 
			
		||||
	Σ *bls.G1Point
 | 
			
		||||
	Proof *verkle.Proof
 | 
			
		||||
 | 
			
		||||
	Cis     []*bls.G1Point
 | 
			
		||||
	Indices []uint
 | 
			
		||||
	Yis     []*bls.Fr
 | 
			
		||||
	Cis     []*verkle.Point
 | 
			
		||||
	Indices []byte
 | 
			
		||||
	Yis     []*verkle.Fr
 | 
			
		||||
 | 
			
		||||
	Leaves []KeyValuePair
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (trie *VerkleTrie) ProveAndSerialize(keys [][]byte, kv map[common.Hash][]byte) ([]byte, error) {
 | 
			
		||||
	d, y, σ, cis, indices, yis := verkle.MakeVerkleMultiProof(trie.root, keys)
 | 
			
		||||
	proof, cis, indices, yis := verkle.MakeVerkleMultiProof(trie.root, keys)
 | 
			
		||||
	vp := verkleproof{
 | 
			
		||||
		D:       d,
 | 
			
		||||
		Y:       y,
 | 
			
		||||
		Σ:       σ,
 | 
			
		||||
		Proof:   proof,
 | 
			
		||||
		Cis:     cis,
 | 
			
		||||
		Indices: indices,
 | 
			
		||||
		Yis:     yis,
 | 
			
		||||
@@ -204,29 +199,29 @@ func (trie *VerkleTrie) ProveAndSerialize(keys [][]byte, kv map[common.Hash][]by
 | 
			
		||||
	return rlp.EncodeToBytes(vp)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func DeserializeAndVerifyVerkleProof(proof []byte) (*bls.G1Point, *bls.Fr, *bls.G1Point, map[common.Hash]common.Hash, error) {
 | 
			
		||||
	d, y, σ, cis, indices, yis, leaves, err := deserializeVerkleProof(proof)
 | 
			
		||||
func DeserializeAndVerifyVerkleProof(serialized []byte) (map[common.Hash]common.Hash, error) {
 | 
			
		||||
	proof, cis, indices, yis, leaves, err := deserializeVerkleProof(serialized)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, nil, nil, nil, fmt.Errorf("could not deserialize proof: %w", err)
 | 
			
		||||
		return nil, fmt.Errorf("could not deserialize proof: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	if !verkle.VerifyVerkleProof(d, σ, y, cis, indices, yis, verkle.GetKZGConfig()) {
 | 
			
		||||
		return nil, nil, nil, nil, errInvalidProof
 | 
			
		||||
	if !verkle.VerifyVerkleProof(proof, cis, indices, yis, verkle.GetConfig()) {
 | 
			
		||||
		return nil, errInvalidProof
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return d, y, σ, leaves, nil
 | 
			
		||||
	return leaves, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func deserializeVerkleProof(proof []byte) (*bls.G1Point, *bls.Fr, *bls.G1Point, []*bls.G1Point, []uint, []*bls.Fr, map[common.Hash]common.Hash, error) {
 | 
			
		||||
func deserializeVerkleProof(proof []byte) (*verkle.Proof, []*verkle.Point, []byte, []*verkle.Fr, map[common.Hash]common.Hash, error) {
 | 
			
		||||
	var vp verkleproof
 | 
			
		||||
	err := rlp.DecodeBytes(proof, &vp)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("verkle proof deserialization error: %w", err)
 | 
			
		||||
		return nil, nil, nil, nil, nil, fmt.Errorf("verkle proof deserialization error: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
	leaves := make(map[common.Hash]common.Hash, len(vp.Leaves))
 | 
			
		||||
	for _, kvp := range vp.Leaves {
 | 
			
		||||
		leaves[common.BytesToHash(kvp.Key)] = common.BytesToHash(kvp.Value)
 | 
			
		||||
	}
 | 
			
		||||
	return vp.D, vp.Y, vp.Σ, vp.Cis, vp.Indices, vp.Yis, leaves, nil
 | 
			
		||||
	return vp.Proof, vp.Cis, vp.Indices, vp.Yis, leaves, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Copy the values here so as to avoid an import cycle
 | 
			
		||||
 
 | 
			
		||||
@@ -21,9 +21,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	"github.com/ethereum/go-ethereum/common"
 | 
			
		||||
	"github.com/ethereum/go-ethereum/ethdb"
 | 
			
		||||
	"github.com/protolambda/go-kzg/bls"
 | 
			
		||||
 | 
			
		||||
	//"github.com/ethereum/go-ethereum/rlp"
 | 
			
		||||
	"github.com/gballet/go-verkle"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -133,13 +131,13 @@ func (it *verkleNodeIterator) Error() error {
 | 
			
		||||
 | 
			
		||||
// Hash returns the hash of the current node.
 | 
			
		||||
func (it *verkleNodeIterator) Hash() common.Hash {
 | 
			
		||||
	return bls.FrTo32(it.current.ComputeCommitment())
 | 
			
		||||
	return it.current.ComputeCommitment().Bytes()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Parent returns the hash of the parent of the current node. The hash may be the one
 | 
			
		||||
// grandparent if the immediate parent is an internal node with no hash.
 | 
			
		||||
func (it *verkleNodeIterator) Parent() common.Hash {
 | 
			
		||||
	return bls.FrTo32(it.stack[len(it.stack)-1].Node.ComputeCommitment())
 | 
			
		||||
	return it.stack[len(it.stack)-1].Node.ComputeCommitment().Bytes()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Path returns the hex-encoded path to the current node.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user