Skip to content

Commit

Permalink
mod: go-ipa panic removal (#389)
Browse files Browse the repository at this point in the history
* mod: go-ipa panic removal

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* mod: use go-ipa master

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
  • Loading branch information
jsign authored Sep 9, 2023
1 parent 300c55f commit 3b1282b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gballet/go-verkle
go 1.19

require (
github.com/crate-crypto/go-ipa v0.0.0-20230904185759-9f7637e8ddd0
github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949
golang.org/x/sync v0.1.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/Yj
github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI=
github.com/consensys/gnark-crypto v0.11.2 h1:GJjjtWJ+db1xGao7vTsOgAOGgjfPe7eRGPL+xxMX0qE=
github.com/consensys/gnark-crypto v0.11.2/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY=
github.com/crate-crypto/go-ipa v0.0.0-20230904185759-9f7637e8ddd0 h1:MztzKYOxMeC8HlWGXvq2wizas+QT0FgITjGThfmbh/0=
github.com/crate-crypto/go-ipa v0.0.0-20230904185759-9f7637e8ddd0/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o=
github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949 h1:m73KBJvYRMuaUth425v6nKeEu6GSq9Zij01+jc2r2Y0=
github.com/crate-crypto/go-ipa v0.0.0-20230905211650-63ccabc1a949/go.mod h1:7fZtshzGQ3dxVpDpF51K9mX8oziq8Xd5AoM/UT9fF5o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
Expand Down
10 changes: 7 additions & 3 deletions proof_ipa.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package verkle
import (
"bytes"
"errors"
"fmt"
"sort"
"unsafe"

Expand Down Expand Up @@ -91,7 +92,7 @@ func MakeVerkleMultiProof(root VerkleNode, keys [][]byte, resolver NodeResolverF

pe, es, poas, err := GetCommitmentsForMultiproof(root, keys, resolver)
if err != nil {
return nil, nil, nil, nil, err
return nil, nil, nil, nil, fmt.Errorf("get commitments for multiproof: %s", err)
}

// NOTE this is leftover code from the time the proof was
Expand All @@ -108,7 +109,10 @@ func MakeVerkleMultiProof(root VerkleNode, keys [][]byte, resolver NodeResolverF
// }

cfg := GetConfig()
mpArg := ipa.CreateMultiProof(tr, cfg.conf, pe.Cis, pe.Fis, pe.Zis)
mpArg, err := ipa.CreateMultiProof(tr, cfg.conf, pe.Cis, pe.Fis, pe.Zis)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("creating multiproof: %s", err)
}

// It's wheel-reinvention time again 🎉: reimplement a basic
// feature that should be part of the stdlib.
Expand Down Expand Up @@ -137,7 +141,7 @@ func MakeVerkleMultiProof(root VerkleNode, keys [][]byte, resolver NodeResolverF
return proof, pe.Cis, pe.Zis, pe.Yis, nil
}

func VerifyVerkleProof(proof *Proof, Cs []*Point, indices []uint8, ys []*Fr, tc *Config) bool {
func VerifyVerkleProof(proof *Proof, Cs []*Point, indices []uint8, ys []*Fr, tc *Config) (bool, error) {
tr := common.NewTranscript("vt")
return ipa.CheckMultiProof(tr, tc.conf, proof.Multipoint, Cs, ys, indices)
}
Expand Down
26 changes: 13 additions & 13 deletions proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestProofVerifyTwoLeaves(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{ffx32KeyTest}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatalf("could not verify verkle proof: %s", ToDot(root))
}
}
Expand All @@ -68,7 +68,7 @@ func TestProofVerifyMultipleLeaves(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{keys[0]}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -94,7 +94,7 @@ func TestMultiProofVerifyMultipleLeaves(t *testing.T) {
t.Fatal(err)
}
cfg := GetConfig()
if !VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg) {
if ok, err := VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestMultiProofVerifyMultipleLeavesWithAbsentStem(t *testing.T) {
}

cfg := GetConfig()
if !VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg) {
if ok, err := VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -159,7 +159,7 @@ func TestMultiProofVerifyMultipleLeavesCommitmentRedundancy(t *testing.T) {
t.Fatal(err)
}
cfg := GetConfig()
if !VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg) {
if ok, err := VerifyVerkleProof(proof, pe.Cis, pe.Zis, pe.Yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -174,7 +174,7 @@ func TestProofOfAbsenceInternalVerify(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{ffx32KeyTest}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -189,7 +189,7 @@ func TestProofOfAbsenceLeafVerify(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{oneKeyTest}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -208,7 +208,7 @@ func TestProofOfAbsenceLeafVerifyOtherSuffix(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{key}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -227,7 +227,7 @@ func TestProofOfAbsenceStemVerify(t *testing.T) {
proof, cis, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{key}, nil)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func TestProofDeserialize(t *testing.T) {
t.Fatal(err)
}
cfg := GetConfig()
if !VerifyVerkleProof(deserialized, pe.Cis, pe.Zis, pe.Yis, cfg) {
if ok, err := VerifyVerkleProof(deserialized, pe.Cis, pe.Zis, pe.Yis, cfg); !ok || err != nil {
t.Fatal("could not verify verkle proof")
}
}
Expand All @@ -392,7 +392,7 @@ func TestProofOfAbsenceEdgeCase(t *testing.T) {
ret, _ := hex.DecodeString("0303030303030303030303030303030303030303030303030303030303030303")
proof, cs, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{ret}, nil)
cfg := GetConfig()
if !VerifyVerkleProof(proof, cs, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cs, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify proof")
}
}
Expand All @@ -411,7 +411,7 @@ func TestProofOfAbsenceOtherMultipleLeaves(t *testing.T) {
ret2, _ := hex.DecodeString("0303030303030303030303030303030303030303030303030303030303030301")
proof, cs, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{ret1, ret2}, nil)
cfg := GetConfig()
if !VerifyVerkleProof(proof, cs, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cs, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify proof")
}

Expand All @@ -432,7 +432,7 @@ func TestProofOfAbsenceNoneMultipleStems(t *testing.T) {
ret2, _ := hex.DecodeString("0303030303030303030303030303030303030303030303030303030303030200")
proof, cs, zis, yis, _ := MakeVerkleMultiProof(root, [][]byte{ret1, ret2}, nil)
cfg := GetConfig()
if !VerifyVerkleProof(proof, cs, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cs, zis, yis, cfg); !ok || err != nil {
t.Fatal("could not verify proof")
}

Expand Down
4 changes: 2 additions & 2 deletions tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ func TestRustBanderwagonBlock48(t *testing.T) {
t.Logf("serialized proof=%v", vp)

cfg := GetConfig()
if !VerifyVerkleProof(proof, cis, zis, yis, cfg) {
if ok, err := VerifyVerkleProof(proof, cis, zis, yis, cfg); !ok || err != nil {
t.Fatal("proof didn't verify")
}

Expand All @@ -1206,7 +1206,7 @@ func TestRustBanderwagonBlock48(t *testing.T) {
t.Fatal(err)
}

if !VerifyVerkleProof(dproof, pe.Cis, pe.Zis, pe.Yis, cfg) {
if ok, err := VerifyVerkleProof(dproof, pe.Cis, pe.Zis, pe.Yis, cfg); !ok || err != nil {
t.Fatal("deserialized proof didn't verify")
}
}
Expand Down

0 comments on commit 3b1282b

Please sign in to comment.