Class: KZG::Commitment
- Inherits:
-
Object
- Object
- KZG::Commitment
- Defined in:
- lib/kzg/commitment.rb
Overview
KZG commitment
Instance Attribute Summary collapse
-
#polynomial ⇒ Object
readonly
Returns the value of attribute polynomial.
-
#setting ⇒ Object
readonly
Returns the value of attribute setting.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.from_coeffs(setting, coeffs) ⇒ Object
Create commitment using coefficients.
Instance Method Summary collapse
-
#compute_multi_proof(x) ⇒ BLS::PointG1
Compute KZG multi proof using list of x coordinate.
-
#compute_proof(x) ⇒ BLS::PointG1
Compute KZG proof for polynomial in coefficient form at position x.
-
#initialize(setting, polynomial) ⇒ Commitment
constructor
Create commitment.
Constructor Details
#initialize(setting, polynomial) ⇒ Commitment
Create commitment
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kzg/commitment.rb', line 11 def initialize(setting, polynomial) @setting = setting @polynomial = polynomial @value = polynomial .coeffs .map .with_index do |c, i| c = c.is_a?(BLS::Fr) ? c : BLS::Fr.new(c) c.value.zero? ? BLS::PointG1::ZERO : setting.g1_points[i] * c end .inject(&:+) end |
Instance Attribute Details
#polynomial ⇒ Object (readonly)
Returns the value of attribute polynomial.
6 7 8 |
# File 'lib/kzg/commitment.rb', line 6 def polynomial @polynomial end |
#setting ⇒ Object (readonly)
Returns the value of attribute setting.
6 7 8 |
# File 'lib/kzg/commitment.rb', line 6 def setting @setting end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/kzg/commitment.rb', line 6 def value @value end |
Class Method Details
.from_coeffs(setting, coeffs) ⇒ Object
Create commitment using coefficients.
28 29 30 31 32 33 34 |
# File 'lib/kzg/commitment.rb', line 28 def self.from_coeffs(setting, coeffs) if coeffs.length > setting.g1_points.length raise KZG::Error, "coeffs length is greater than the number of secret parameters." end Commitment.new(setting, KZG::Polynomial.new(coeffs)) end |
Instance Method Details
#compute_multi_proof(x) ⇒ BLS::PointG1
Compute KZG multi proof using list of x coordinate.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kzg/commitment.rb', line 48 def compute_multi_proof(x) y = x.map { |i| polynomial.eval_at(i) } # compute i(x) i_poly = Polynomial.lagrange_interpolate(x, y) # compute z(x) z_poly = Polynomial.zero_poly(x) # compute q(x) = (p(x) - i(x)) / z(x) quotient_poly = (polynomial - i_poly) / z_poly Commitment.new(setting, quotient_poly).value end |
#compute_proof(x) ⇒ BLS::PointG1
Compute KZG proof for polynomial in coefficient form at position x.
39 40 41 42 43 |
# File 'lib/kzg/commitment.rb', line 39 def compute_proof(x) divisor = Polynomial.new([BLS::Fr.new(x).negate, BLS::Fr::ONE]) quotient_poly = polynomial / divisor Commitment.new(setting, quotient_poly).value end |