diff --git a/constraint/solver/hint_registry.go b/constraint/solver/hint_registry.go index fa5d44d357..418407fa37 100644 --- a/constraint/solver/hint_registry.go +++ b/constraint/solver/hint_registry.go @@ -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" ) @@ -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. diff --git a/examples/rollup/circuit.go b/examples/rollup/circuit.go index 8dc8ae8114..170a11c163 100644 --- a/examples/rollup/circuit.go +++ b/examples/rollup/circuit.go @@ -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 diff --git a/examples/rollup/operator.go b/examples/rollup/operator.go index d87e6390ef..facf8d90ed 100644 --- a/examples/rollup/operator.go +++ b/examples/rollup/operator.go @@ -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 } @@ -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] diff --git a/frontend/schema/tags.go b/frontend/schema/tags.go index 042a22fbc0..17223162b0 100644 --- a/frontend/schema/tags.go +++ b/frontend/schema/tags.go @@ -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 diff --git a/std/algebra/emulated/sw_bn254/pairing.go b/std/algebra/emulated/sw_bn254/pairing.go index 6831e31b71..a1fd64f33b 100644 --- a/std/algebra/emulated/sw_bn254/pairing.go +++ b/std/algebra/emulated/sw_bn254/pairing.go @@ -770,7 +770,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. diff --git a/std/polynomial/polynomial.go b/std/polynomial/polynomial.go index f6566c0ba0..7c40f44336 100644 --- a/std/polynomial/polynomial.go +++ b/std/polynomial/polynomial.go @@ -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)) } }