Skip to content

Commit

Permalink
Add validation the number of commitment_list and sig_shares mismatch …
Browse files Browse the repository at this point in the history
…in aggregate
  • Loading branch information
azuchi committed Feb 11, 2024
1 parent 48d3287 commit efcd822
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/frost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def sign(secret_share, group_pubkey, nonces, msg, commitment_list)
def aggregate(commitment_list, msg, group_pubkey, sig_shares)
raise ArgumentError, "msg must be String." unless msg.is_a?(String)
raise ArgumentError, "group_pubkey must be ECDSA::Point." unless group_pubkey.is_a?(ECDSA::Point)
raise ArgumentError, "The numbers of commitment_list and sig_shares do not match." unless commitment_list.length == sig_shares.length

binding_factors = compute_binding_factors(group_pubkey, commitment_list, msg)
group_commitment = compute_group_commitment(commitment_list, binding_factors)
Expand Down
19 changes: 17 additions & 2 deletions spec/frost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

RSpec.describe FROST do

let(:group) { ECDSA::Group::Secp256k1 }

shared_examples "Test Vector" do
it do
# key generation
Expand Down Expand Up @@ -112,14 +114,12 @@

describe "Test Vector" do
context "secp256k1" do
let(:group) { ECDSA::Group::Secp256k1 }
let(:vectors) { load_fixture("secp256k1/vectors.json") }
it_behaves_like "Test Vector", "secp256k1"
it_behaves_like "frost process", "secp256k1"
end

context "secp256k1 big identifiers" do
let(:group) { ECDSA::Group::Secp256k1 }
let(:vectors) { load_fixture("secp256k1/vectors-big-identifier.json") }
it_behaves_like "Test Vector", "secp256k1 with big identifier"
end
Expand All @@ -138,4 +138,19 @@
end
end

describe "#aggregate" do
context "with long commitment list" do
it do
secret = FROST::SigningKey.generate(group)
group_pubkey = secret.to_point
comm1 = FROST::Commitments.new(1, group_pubkey, group_pubkey) # fake commitments
comm2 = FROST::Commitments.new(2, group_pubkey, group_pubkey) # fake commitments
comm3 = FROST::Commitments.new(3, group_pubkey, group_pubkey) # fake commitments
msg = ""
sig_shares = [1, 2]
expect{ described_class.aggregate([comm1, comm2, comm3], msg, group_pubkey, sig_shares) }.
to raise_error("The numbers of commitment_list and sig_shares do not match.")
end
end
end
end

0 comments on commit efcd822

Please sign in to comment.