Skip to content

Commit

Permalink
Implement FROST::DKG::Package#verify_share
Browse files Browse the repository at this point in the history
  • Loading branch information
azuchi committed Feb 14, 2024
1 parent 67c656c commit 1255a7b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/frost/dkg/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ def initialize(identifier, commitments, proof)
def verification_key
commitments.first
end

# Verify share.
# @param [FROST::SecretShare] share
# @return [Boolean]
def verify_share(share)
x = share.identifier
result = commitments[1..-1].inject(commitments.first) do |sum, com|
tmp = com * x
x *= x
sum + tmp
end
result == share.to_point
end
end
end
end
25 changes: 24 additions & 1 deletion spec/frost/dkg_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

secrets = {}
round1_outputs = {}
# Round 1: For each participant, perform the first part of the DKG protocol.
# Round 1:
# For each participant, perform the first part of the DKG protocol.
1.upto(max_signer) do |i|
polynomial, package = FROST::DKG.part1(i, min_signer, max_signer, group)
secrets[i] = polynomial
Expand All @@ -30,6 +31,28 @@
expect(FROST::DKG.verify_proof_of_knowledge(package)).to be true
end
end

# Round 2:
# Each participant generate share for other participants.
received_shares = {}
1.upto(max_signer) do |i|
polynomial = secrets[i] # own secret
1.upto(max_signer) do |o|
next if i == o
received_shares[o] ||= []
received_shares[o] << polynomial.gen_share(i)
end
end

# Each participant verify received shares.
1.upto(max_signer) do |i|
received_shares[i].each do |share|
target_package = received_package[i].find{|package| package.identifier == share.identifier}
(min_signer - 1).times do |degree|
expect(target_package.verify_share(share)).to be true
end
end
end
end
end

Expand Down

0 comments on commit 1255a7b

Please sign in to comment.