Skip to content

Commit

Permalink
feat(galois): upgrade circuit to latest gnark
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Nov 2, 2023
1 parent b75cd34 commit 79516cc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions galoisd/pkg/lightclient/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import (
"github.com/consensys/gnark/std/math/emulated"
)

// NOTE: this circuit is compatible with the bn254 backend ONLY as we assume
// that the scalar field is the one from this curve for many public inputs.

// Max number of validators this lc can handle
const MaxVal = 16
// Max number of validators the light client can handle
const MaxVal = 128

type Validator struct {
HashableX frontend.Variable
Expand Down Expand Up @@ -128,7 +125,7 @@ func (lc *TendermintLightClientAPI) Verify(message *gadget.G2Affine, expectedVal
currentVotingPower = lc.api.Add(currentVotingPower, lc.api.Select(signed, power, 0))
// Optionally aggregated public key if validator at index signed
firstPK := lc.api.And(signed, lc.api.IsZero(aggregatedKeys))
aggregated := curveArithmetic.AddUnified(&aggregatedPublicKey, curveArithmetic.Select(signed, publicKey, &gadget.G1Affine{}))
aggregated := curveArithmetic.AddUnified(&aggregatedPublicKey, curveArithmetic.Select(signed, publicKey, &emulatedG1Zero))
aggregateNext := curveArithmetic.Select(firstPK, publicKey, aggregated)
aggregatedPublicKey =
*curveArithmetic.Select(signed, aggregateNext, &aggregatedPublicKey)
Expand Down Expand Up @@ -165,19 +162,14 @@ func (lc *TendermintLightClientAPI) Verify(message *gadget.G2Affine, expectedVal
var g1AffGenNeg curve.G1Affine
g1AffGenNeg.Neg(&g1AffGen)
negG1 := gadget.NewG1Affine(g1AffGenNeg)
e, err := pairing.Pair(

err = pairing.PairingCheck(
[]*gadget.G1Affine{&negG1, &aggregatedPublicKey},
[]*gadget.G2Affine{&lc.input.Sig, message},
)
if err != nil {
return fmt.Errorf("pair: %w", err)
}

var oneN curve.GT
oneN.SetOne()
one := gadget.NewGTEl(oneN)

pairing.AssertIsEqual(e, &one)

return nil
}
2 changes: 1 addition & 1 deletion galoisd/pkg/merkle/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
)

type MerkleTreeAPI struct {
api frontend.API
api frontend.API
}

func NewMerkleTreeAPI(api frontend.API) *MerkleTreeAPI {
Expand Down

0 comments on commit 79516cc

Please sign in to comment.