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_proof(x) ⇒ BLS::PointG1
Compute KZG proof for polynomial in coefficient form at position x.
-
#initialize(setting, polynomial, value) ⇒ Commitment
constructor
Create commitment.
Constructor Details
#initialize(setting, polynomial, value) ⇒ Commitment
Create commitment
11 12 13 14 15 |
# File 'lib/kzg/commitment.rb', line 11 def initialize(setting, polynomial, value) @setting = setting @polynomial = polynomial @value = value 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.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kzg/commitment.rb', line 20 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 value = 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(&:+) Commitment.new(setting, KZG::Polynomial.new(coeffs), value) end |
Instance Method Details
#compute_proof(x) ⇒ BLS::PointG1
Compute KZG proof for polynomial in coefficient form at position x.
39 40 41 42 43 44 45 |
# File 'lib/kzg/commitment.rb', line 39 def compute_proof(x) divisor = Array.new(2) divisor[0] = BLS::Fr.new(x).negate divisor[1] = BLS::Fr::ONE quotient_poly = polynomial.poly_long_div(divisor) Commitment.from_coeffs(setting, quotient_poly).value end |