Class: KZG::Commitment

Inherits:
Object
  • Object
show all
Defined in:
lib/kzg/commitment.rb

Overview

KZG commitment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setting, polynomial, value) ⇒ Commitment

Create commitment

Parameters:

  • setting (KZG::Setting)
  • coeffs (Array(Integer | BLS::Fr))

    Coefficients of polynomial equation.



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

#polynomialObject (readonly)

Returns the value of attribute polynomial.



6
7
8
# File 'lib/kzg/commitment.rb', line 6

def polynomial
  @polynomial
end

#settingObject (readonly)

Returns the value of attribute setting.



6
7
8
# File 'lib/kzg/commitment.rb', line 6

def setting
  @setting
end

#valueObject (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.

Parameters:

  • setting (KZG::Setting)
  • coeffs (Array(Integer | BLS::Fr))

    Coefficients of polynomial equation.



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.

Parameters:

  • x (Integer)

    Position

Returns:

  • (BLS::PointG1)

    Proof.



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