mirror of
https://github.com/arnaucube/gnark-plonky2-verifier.git
synced 2026-01-12 09:01:32 +01:00
fix for V-SCT-VUL-027
This commit is contained in:
@@ -87,38 +87,41 @@ func New(api frontend.API) *Chip {
|
||||
return &Chip{api: api, rangeChecker: rangeChecker}
|
||||
}
|
||||
|
||||
// Adds two field elements such that x + y = z within the Golidlocks field.
|
||||
// Adds two goldilocks field elements and returns a value within the goldilocks field.
|
||||
func (p *Chip) Add(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(a, NewVariable(1), b)
|
||||
}
|
||||
|
||||
// Adds two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||
// Adds two goldilocks field elements and returns a value that may not be within the goldilocks field
|
||||
// (e.g. the sum is not reduced).
|
||||
func (p *Chip) AddNoReduce(a Variable, b Variable) Variable {
|
||||
return NewVariable(p.api.Add(a.Limb, b.Limb))
|
||||
}
|
||||
|
||||
// Subtracts two field elements such that x + y = z within the Golidlocks field.
|
||||
// Subracts two goldilocks field elements and returns a value within the goldilocks field.
|
||||
func (p *Chip) Sub(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(b, NegOne(), a)
|
||||
}
|
||||
|
||||
// Subtracts two field elements such that x + y = z within the Golidlocks field without reducing.
|
||||
// Subracts two goldilocks field elements and returns a value that may not be within the goldilocks field
|
||||
// (e.g. the difference is not reduced).
|
||||
func (p *Chip) SubNoReduce(a Variable, b Variable) Variable {
|
||||
return NewVariable(p.api.Add(a.Limb, p.api.Mul(b.Limb, NegOne().Limb)))
|
||||
}
|
||||
|
||||
// Multiplies two field elements such that x * y = z within the Golidlocks field.
|
||||
// Multiplies two goldilocks field elements and returns a value within the goldilocks field.
|
||||
func (p *Chip) Mul(a Variable, b Variable) Variable {
|
||||
return p.MulAdd(a, b, Zero())
|
||||
}
|
||||
|
||||
// Multiplies two field elements such that x * y = z within the Golidlocks field without reducing.
|
||||
// Multiplies two goldilocks field elements and returns a value that may not be within the goldilocks field
|
||||
// (e.g. the product is not reduced).
|
||||
func (p *Chip) MulNoReduce(a Variable, b Variable) Variable {
|
||||
return NewVariable(p.api.Mul(a.Limb, b.Limb))
|
||||
}
|
||||
|
||||
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
||||
// Golidlocks field.
|
||||
// Multiplies two field elements and adds a field element (e.g. computes a * b + c). The returned value
|
||||
// will be within the goldilocks field.
|
||||
func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable {
|
||||
result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb)
|
||||
if err != nil {
|
||||
@@ -138,8 +141,8 @@ func (p *Chip) MulAdd(a Variable, b Variable, c Variable) Variable {
|
||||
return remainder
|
||||
}
|
||||
|
||||
// Multiplies two field elements and adds a field element such that x * y + z = c within the
|
||||
// Golidlocks field without reducing.
|
||||
// Multiplies two field elements and adds a field element (e.g. computes a * b + c). The returned value
|
||||
// may no be within the goldilocks field (e.g. the result is not reduced).
|
||||
func (p *Chip) MulAddNoReduce(a Variable, b Variable, c Variable) Variable {
|
||||
cLimbCopy := p.api.Mul(c.Limb, 1)
|
||||
return NewVariable(p.api.MulAcc(cLimbCopy, a.Limb, b.Limb))
|
||||
|
||||
@@ -84,7 +84,7 @@ func (p *Chip) MulAddExtensionNoReduce(a, b, c QuadraticExtensionVariable) Quadr
|
||||
return sum
|
||||
}
|
||||
|
||||
// Multiplies two operands a and b and subtracts to c in the Goldilocks extension field. a * b - c must
|
||||
// Subtracts two operands a and b and multiplies the diff by c in the Goldilocks extension field. (a - b) * c must
|
||||
// be less than RANGE_CHECK_NB_BITS bits.
|
||||
func (p *Chip) SubMulExtension(a, b, c QuadraticExtensionVariable) QuadraticExtensionVariable {
|
||||
difference := p.SubExtensionNoReduce(a, b)
|
||||
@@ -209,7 +209,7 @@ func (p *Chip) Lookup(
|
||||
return NewQuadraticExtensionVariable(NewVariable(c0), NewVariable(c1))
|
||||
}
|
||||
|
||||
// Lookup2 is similar to select2, but returns the first variable if the bit is zero and vice-versa.
|
||||
// Lookup2 is similar to Lookup2. It returns the ith qe value (0 indexed) where i is bit decomposed to b0,b1 (little endian).
|
||||
func (p *Chip) Lookup2(
|
||||
b0 frontend.Variable,
|
||||
b1 frontend.Variable,
|
||||
|
||||
Reference in New Issue
Block a user