From bc7fa641294f6105d60fbf57a86b598907084e6d Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Mon, 21 Oct 2024 13:54:27 -0300 Subject: [PATCH 1/5] add proof Equal methods Signed-off-by: Ignacio Hagopian --- proof_ipa.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/proof_ipa.go b/proof_ipa.go index c1f20815..f553c848 100644 --- a/proof_ipa.go +++ b/proof_ipa.go @@ -73,6 +73,35 @@ func (vp *VerkleProof) Copy() *VerkleProof { return ret } +func (vp *VerkleProof) Equal(other *VerkleProof) error { + if len(vp.OtherStems) != len(other.OtherStems) { + return fmt.Errorf("different number of other stems: %d != %d", len(vp.OtherStems), len(other.OtherStems)) + } + for i := range vp.OtherStems { + if vp.OtherStems[i] != other.OtherStems[i] { + return fmt.Errorf("different other stem: %x != %x", vp.OtherStems[i], other.OtherStems[i]) + } + } + if len(vp.DepthExtensionPresent) != len(other.DepthExtensionPresent) { + return fmt.Errorf("different number of depth extension present: %d != %d", len(vp.DepthExtensionPresent), len(other.DepthExtensionPresent)) + } + if !bytes.Equal(vp.DepthExtensionPresent, other.DepthExtensionPresent) { + return fmt.Errorf("different depth extension present: %x != %x", vp.DepthExtensionPresent, other.DepthExtensionPresent) + } + if len(vp.CommitmentsByPath) != len(other.CommitmentsByPath) { + return fmt.Errorf("different number of commitments by path: %d != %d", len(vp.CommitmentsByPath), len(other.CommitmentsByPath)) + } + for i := range vp.CommitmentsByPath { + if vp.CommitmentsByPath[i] != other.CommitmentsByPath[i] { + return fmt.Errorf("different commitment by path: %x != %x", vp.CommitmentsByPath[i], other.CommitmentsByPath[i]) + } + } + if vp.D != other.D { + return fmt.Errorf("different D: %x != %x", vp.D, other.D) + } + return nil +} + type Proof struct { Multipoint *ipa.MultiProof // multipoint argument ExtStatus []byte // the extension status of each stem @@ -118,6 +147,40 @@ func (sd StateDiff) Copy() StateDiff { return ret } +func (sd StateDiff) Equal(other StateDiff) error { + if len(sd) != len(other) { + return fmt.Errorf("different number of stem state diffs: %d != %d", len(sd), len(other)) + } + for i := range sd { + if sd[i].Stem != other[i].Stem { + return fmt.Errorf("different stem: %x != %x", sd[i].Stem, other[i].Stem) + } + if len(sd[i].SuffixDiffs) != len(other[i].SuffixDiffs) { + return fmt.Errorf("different number of suffix state diffs: %d != %d", len(sd[i].SuffixDiffs), len(other[i].SuffixDiffs)) + } + for j := range sd[i].SuffixDiffs { + if sd[i].SuffixDiffs[j].Suffix != other[i].SuffixDiffs[j].Suffix { + return fmt.Errorf("different suffix: %x != %x", sd[i].SuffixDiffs[j].Suffix, other[i].SuffixDiffs[j].Suffix) + } + if sd[i].SuffixDiffs[j].CurrentValue != nil && other[i].SuffixDiffs[j].CurrentValue != nil { + if *sd[i].SuffixDiffs[j].CurrentValue != *other[i].SuffixDiffs[j].CurrentValue { + return fmt.Errorf("different current value: %x != %x", *sd[i].SuffixDiffs[j].CurrentValue, *other[i].SuffixDiffs[j].CurrentValue) + } + } else if sd[i].SuffixDiffs[j].CurrentValue != nil || other[i].SuffixDiffs[j].CurrentValue != nil { + return fmt.Errorf("different current value: %x != %x", sd[i].SuffixDiffs[j].CurrentValue, other[i].SuffixDiffs[j].CurrentValue) + } + if sd[i].SuffixDiffs[j].NewValue != nil && other[i].SuffixDiffs[j].NewValue != nil { + if *sd[i].SuffixDiffs[j].NewValue != *other[i].SuffixDiffs[j].NewValue { + return fmt.Errorf("different new value: %x != %x", *sd[i].SuffixDiffs[j].NewValue, *other[i].SuffixDiffs[j].NewValue) + } + } else if sd[i].SuffixDiffs[j].NewValue != nil || other[i].SuffixDiffs[j].NewValue != nil { + return fmt.Errorf("different new value: %x != %x", sd[i].SuffixDiffs[j].NewValue, other[i].SuffixDiffs[j].NewValue) + } + } + } + return nil +} + func GetCommitmentsForMultiproof(root VerkleNode, keys [][]byte, resolver NodeResolverFn) (*ProofElements, []byte, []Stem, error) { sort.Sort(keylist(keys)) return root.GetProofItems(keylist(keys), resolver) From af83a4269ec8719f60e5e778575385afd3825b4a Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Mon, 21 Oct 2024 16:55:16 -0300 Subject: [PATCH 2/5] execution spec test workaround Signed-off-by: Ignacio Hagopian --- proof_json.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/proof_json.go b/proof_json.go index 7828697e..f1d6c366 100644 --- a/proof_json.go +++ b/proof_json.go @@ -42,6 +42,10 @@ func PrefixedHexStringToBytes(input string) ([]byte, error) { if input[0:2] == "0x" { input = input[2:] } + // TODO(jsign): workaround for execution-spec-tests bug. Remove as soon as it's fixed. + if len(input)%2 != 0 { + input = "0" + input + } return hex.DecodeString(input) } From 83b0edbd43507f9119cc6fd7ba1d53a11fbd2b25 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Mon, 21 Oct 2024 17:37:37 -0300 Subject: [PATCH 3/5] add nil check Signed-off-by: Ignacio Hagopian --- proof_ipa.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/proof_ipa.go b/proof_ipa.go index f553c848..15d4e8a8 100644 --- a/proof_ipa.go +++ b/proof_ipa.go @@ -53,6 +53,9 @@ type VerkleProof struct { } func (vp *VerkleProof) Copy() *VerkleProof { + if vp == nil { + return nil + } ret := &VerkleProof{ OtherStems: make([][StemSize]byte, len(vp.OtherStems)), DepthExtensionPresent: make([]byte, len(vp.DepthExtensionPresent)), From dbc740b0bdd9c2cc423cb0fda6b17ed12e137728 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Thu, 24 Oct 2024 11:40:33 -0300 Subject: [PATCH 4/5] revert workaround Signed-off-by: Ignacio Hagopian --- proof_json.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/proof_json.go b/proof_json.go index f1d6c366..7828697e 100644 --- a/proof_json.go +++ b/proof_json.go @@ -42,10 +42,6 @@ func PrefixedHexStringToBytes(input string) ([]byte, error) { if input[0:2] == "0x" { input = input[2:] } - // TODO(jsign): workaround for execution-spec-tests bug. Remove as soon as it's fixed. - if len(input)%2 != 0 { - input = "0" + input - } return hex.DecodeString(input) } From e0e8b3faecb65ae2e59d3aa4336d65c598f93d2b Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Thu, 24 Oct 2024 13:42:09 -0300 Subject: [PATCH 5/5] readme: nit Signed-off-by: Ignacio Hagopian --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1946b93f..88c8ff20 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ > A Go implementation of Verkle Tree datastructure defined in the [spec](https://github.com/crate-crypto/verkle-trie-ref/tree/master/verkle). - ## Test & Benchmarks To run the tests and benchmarks, run the following commands: