Skip to content

Commit

Permalink
fix 7 out of 10 multi-sig test;
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Mar 13, 2023
1 parent bbdc278 commit cd9fe80
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 19 deletions.
62 changes: 48 additions & 14 deletions ergo-lib/src/wallet/multi_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,8 @@ mod tests {

#[test]
fn multi_sig_atleast_7_out_of_10_i692() {
// based on
// https://github.com/ScorexFoundation/sigmastate-interpreter/blob/78dd1e715038c2f95c518fb56977c6591b76e20c/sc/src/test/scala/sigmastate/utxo/DistributedSigSpecification.scala#L299-L389
let ctx = Rc::new(force_any_val::<Context>());

let sk1 = DlogProverInput::random();
Expand Down Expand Up @@ -1402,6 +1404,8 @@ mod tests {
.sigma_prop;
let message = vec![0u8; 100];

// only actors 1, 2, 3, 4, 5, 6, 7 are signing, others are simulated (see bag_one below)

let hints_1 = generate_commitments_for(&expr_reduced, &[pk1.clone().into()]);
let dl_1_known = hints_1.real_commitments().first().unwrap().clone();
let secret_cmt_1 = hints_1.own_commitments().first().unwrap().clone();
Expand Down Expand Up @@ -1461,6 +1465,7 @@ mod tests {
"Proof generated by Prover7 only is not correct"
);

//hints after the first real proof done.
let bag_one = bag_for_multi_sig(
&expr_reduced,
&[pk7.into()],
Expand All @@ -1469,6 +1474,7 @@ mod tests {
)
.unwrap();

//now real proofs can be done in any order
let mut bag_2 = bag_one.clone();
bag_2.add_hint(secret_cmt_2.clone().into());
bag_2.add_hint(dl_1_known.clone().into());
Expand All @@ -1480,7 +1486,12 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_2)
.unwrap();
let partial_proof_2 =
bag_for_multi_sig(&expr_reduced, &[pk2.into()], &[], proof_2.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk2.into()], &[], proof_2.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag_1 = bag_one.clone();
bag_1.add_hint(secret_cmt_1.clone().into());
Expand All @@ -1494,7 +1505,12 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_1)
.unwrap();
let partial_proof_1 =
bag_for_multi_sig(&expr_reduced, &[pk1.into()], &[], proof_1.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk1.into()], &[], proof_1.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag_3 = bag_one.clone();
bag_3.add_hint(secret_cmt_3.clone().into());
Expand All @@ -1507,7 +1523,12 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_3)
.unwrap();
let partial_proof_3 =
bag_for_multi_sig(&expr_reduced, &[pk3.into()], &[], proof_3.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk3.into()], &[], proof_3.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag_4 = bag_one.clone();
bag_4.add_hint(secret_cmt_4.clone().into());
Expand All @@ -1520,7 +1541,12 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_4)
.unwrap();
let partial_proof_4 =
bag_for_multi_sig(&expr_reduced, &[pk4.into()], &[], proof_4.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk4.into()], &[], proof_4.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag_5 = bag_one.clone();
bag_5.add_hint(secret_cmt_5.clone().into());
Expand All @@ -1533,7 +1559,12 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_5)
.unwrap();
let partial_proof_5 =
bag_for_multi_sig(&expr_reduced, &[pk5.into()], &[], proof_5.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk5.into()], &[], proof_5.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag_6 = bag_one.clone();
bag_6.add_hint(secret_cmt_6.clone().into());
Expand All @@ -1546,15 +1577,20 @@ mod tests {
.prove(&tree_expr, &Env::empty(), ctx.clone(), &message, &bag_6)
.unwrap();
let partial_proof_6 =
bag_for_multi_sig(&expr_reduced, &[pk6.into()], &[], proof_6.proof.as_ref());
bag_for_multi_sig(&expr_reduced, &[pk6.into()], &[], proof_6.proof.as_ref())
.unwrap()
.real_proofs()
.first()
.unwrap()
.clone();

let mut bag = bag_one;
bag.add_bag(partial_proof_1.unwrap());
bag.add_bag(partial_proof_2.unwrap());
bag.add_bag(partial_proof_3.unwrap());
bag.add_bag(partial_proof_4.unwrap());
bag.add_bag(partial_proof_5.unwrap());
bag.add_bag(partial_proof_6.unwrap());
bag.add_hint(partial_proof_1.into());
bag.add_hint(partial_proof_2.into());
bag.add_hint(partial_proof_3.into());
bag.add_hint(partial_proof_4.into());
bag.add_hint(partial_proof_5.into());
bag.add_hint(partial_proof_6.into());
bag.add_hint(dl_1_known.into());
bag.add_hint(dl_2_known.into());
bag.add_hint(dl_3_known.into());
Expand Down Expand Up @@ -1611,8 +1647,6 @@ mod tests {
.result,
);

// TODO: add proofs from 3, 4, 5, 6, 7 provers

let mut valid_bag_3 = bag.clone();
valid_bag_3.add_hint(secret_cmt_3.into());
let valid_proof_3 = prover3
Expand Down
11 changes: 6 additions & 5 deletions ergotree-interpreter/src/sigma_protocol/prover/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ impl From<OwnCommitment> for Hint {
}
}

impl From<RealSecretProof> for Hint {
fn from(p: RealSecretProof) -> Self {
Hint::SecretProven(p.into())
}
}

/// Collection of hints to be used by a prover
#[cfg_attr(feature = "json", derive(serde::Serialize, serde::Deserialize))]
#[derive(PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -241,11 +247,6 @@ impl HintsBag {
self.hints.push(hint);
}

/// Adding new hints from the given bag
pub fn add_bag(&mut self, bag: HintsBag) {
self.hints.extend(bag.hints);
}

/// Commitments from all CommitmentHints in the bag
pub fn commitments(&self) -> Vec<CommitmentHint> {
self.hints
Expand Down

0 comments on commit cd9fe80

Please sign in to comment.