Skip to content

Commit

Permalink
fix: stashed typo fixes for v0.12 (Consensys#1398)
Browse files Browse the repository at this point in the history
Signed-off-by: oliveredget <[email protected]>
Signed-off-by: dashangcun <[email protected]>
Signed-off-by: zhuhaicity <[email protected]>
Signed-off-by: hidewrong <[email protected]>
Co-authored-by: oliveredget <[email protected]>
Co-authored-by: dashangcun <[email protected]>
Co-authored-by: ZhuHaiCheng <[email protected]>
Co-authored-by: hidewrong <[email protected]>
Co-authored-by: VolodymyrBg <[email protected]>
  • Loading branch information
6 people authored Jan 21, 2025
1 parent 5a846d1 commit ac1472a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 27 deletions.
13 changes: 3 additions & 10 deletions constraint/solver/hint_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package solver

import (
"fmt"
"github.com/consensys/gnark/internal/hints"
"maps"
"math/big"
"sync"

"github.com/consensys/gnark/internal/hints"
"github.com/consensys/gnark/logger"
)

Expand Down Expand Up @@ -60,18 +61,10 @@ func GetRegisteredHints() []Hint {
return ret
}

func cloneMap[K comparable, V any](src map[K]V) map[K]V {
res := make(map[K]V, len(registry))
for k, v := range src {
res[k] = v
}
return res
}

func cloneHintRegistry() map[HintID]Hint {
registryM.Lock()
defer registryM.Unlock()
return cloneMap(registry)
return maps.Clone(registry)
}

// InvZeroHint computes the value 1/a for the single input a. If a == 0, returns 0.
Expand Down
4 changes: 2 additions & 2 deletions examples/rollup/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

const (
nbAccounts = 16 // 16 accounts so we know that the proof length is 5
depth = 5 // size fo the inclusion proofs
BatchSizeCircuit = 1 // nbTranfers to batch in a proof
depth = 5 // size of the inclusion proofs
BatchSizeCircuit = 1 // nbTransfers to batch in a proof
)

// Circuit "toy" rollup circuit where an operator can generate a proof that he processed
Expand Down
8 changes: 4 additions & 4 deletions examples/rollup/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (o *Operator) updateState(t Transfer, numTransfer int) error {
if err != nil {
return err
}
merkleRootAfer, proofInclusionSenderAfter, _, err := merkletree.BuildReaderProof(&buf, o.h, segmentSize, posSender)
merkleRootAfter, proofInclusionSenderAfter, _, err := merkletree.BuildReaderProof(&buf, o.h, segmentSize, posSender)
if err != nil {
return err
}
Expand All @@ -247,9 +247,9 @@ func (o *Operator) updateState(t Transfer, numTransfer int) error {
}
// merkleProofHelperReceiverAfter := merkle.GenerateProofHelper(proofInclusionReceiverAfter, posReceiver, numLeaves)

o.witnesses.RootHashesAfter[numTransfer] = merkleRootAfer
o.witnesses.MerkleProofReceiverAfter[numTransfer].RootHash = merkleRootAfer
o.witnesses.MerkleProofSenderAfter[numTransfer].RootHash = merkleRootAfer
o.witnesses.RootHashesAfter[numTransfer] = merkleRootAfter
o.witnesses.MerkleProofReceiverAfter[numTransfer].RootHash = merkleRootAfter
o.witnesses.MerkleProofSenderAfter[numTransfer].RootHash = merkleRootAfter

for i := 0; i < len(proofInclusionSenderAfter); i++ {
o.witnesses.MerkleProofReceiverAfter[numTransfer].Path[i] = proofInclusionReceiverAfter[i]
Expand Down
6 changes: 2 additions & 4 deletions frontend/schema/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ type tagOptions string
// parseTag splits a struct field's json tag into its name and
// comma-separated options.
func parseTag(tag string) (string, tagOptions) {
if idx := strings.Index(tag, ","); idx != -1 {
return tag[:idx], tagOptions(tag[idx+1:])
}
return tag, tagOptions("")
name, remainder, _ := strings.Cut(tag, ",")
return name, tagOptions(remainder)
}

// contains reports whether a comma-separated list of options
Expand Down
2 changes: 1 addition & 1 deletion std/algebra/emulated/sw_bn254/pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ func (pr Pairing) millerLoopAndFinalExpResult(P *G1Affine, Q *G2Affine, previous
}

// IsMillerLoopAndFinalExpOne computes the Miller loop between P and Q,
// multiplies it in 𝔽p¹² by previous and and returns a boolean indicating if
// multiplies it in 𝔽p¹² by previous and returns a boolean indicating if
// the result lies in the same equivalence class as the reduced pairing
// purported to be 1. This check replaces the final exponentiation step
// in-circuit and follows Section 4 of [On Proving Pairings] paper by A.
Expand Down
8 changes: 2 additions & 6 deletions std/polynomial/polynomial.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,13 @@ func negFactorial(n int) int {
// computeDeltaAtNaive brute forces the computation of the δᵢ(at)
func computeDeltaAtNaive(api frontend.API, at frontend.Variable, valuesLen int) []frontend.Variable {
deltaAt := make([]frontend.Variable, valuesLen)
atMinus := make([]frontend.Variable, valuesLen) //TODO: No need for this array and the following loop
for i := range atMinus {
atMinus[i] = api.Sub(at, i)
}
factInv := api.Inverse(negFactorial(valuesLen - 1))

for i := range deltaAt {
deltaAt[i] = factInv
for j := range atMinus {
for j := 0; j < valuesLen; j++ {
if i != j {
deltaAt[i] = api.Mul(deltaAt[i], atMinus[j])
deltaAt[i] = api.Mul(deltaAt[i], api.Sub(at, j))
}
}

Expand Down

0 comments on commit ac1472a

Please sign in to comment.