This repository was archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
MuSig: add counterparties #229
Merged
Merged
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3d5dc67
fille out counterparty state transitions
cathieyun 99f4ca1
add counterparty structs, fix some typos, rename prover->signer
cathieyun 8135ffd
implement counterparty. have not updated signer, not compiling
cathieyun 5b859a7
fix up signer so it compiles & passes tests
cathieyun 1248770
cleanup
cathieyun ff6e004
change aggregation transcript, update tests
cathieyun edc4f15
change phrasing for 'message has already been committed to transcript'
cathieyun fc41b20
more phrasing changes for transcript msg, address PR feedback
cathieyun 36df350
non-inlined `receive_shares` function, `sign` now takes `self`
cathieyun be1bbea
make all counterparty functions pub(super)
cathieyun 9b360bb
clean up imports, use 'super' instead of 'crate::signature'
cathieyun e705c69
make MuSig signature store CompressedRistretto, to make it easier to …
cathieyun cfdaac1
replace all 'P' tags with 'X', for consistency across protocol
cathieyun c549bf0
update comment, sum from iterator directly
cathieyun cb8e58a
make travis re-run
cathieyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| use crate::errors::VMError; | ||
| use crate::signature::multikey::Multikey; | ||
| use crate::signature::VerificationKey; | ||
| use crate::transcript::TranscriptProtocol; | ||
| use curve25519_dalek::constants::RISTRETTO_BASEPOINT_POINT; | ||
| use curve25519_dalek::ristretto::RistrettoPoint; | ||
| use curve25519_dalek::scalar::Scalar; | ||
| use merlin::Transcript; | ||
| use subtle::ConstantTimeEq; | ||
|
|
||
| #[derive(Copy, Clone)] | ||
| pub struct NoncePrecommitment([u8; 32]); | ||
|
|
||
| #[derive(Copy, Clone, Debug)] | ||
| pub struct NonceCommitment(RistrettoPoint); | ||
|
|
||
| impl NonceCommitment { | ||
| pub fn new(commitment: RistrettoPoint) -> Self { | ||
| NonceCommitment(commitment) | ||
| } | ||
|
|
||
| pub fn precommit(&self) -> NoncePrecommitment { | ||
| let mut h = Transcript::new(b"MuSig.nonce-precommit"); | ||
| h.commit_point(b"R", &self.0.compress()); | ||
| let mut precommitment = [0u8; 32]; | ||
| h.challenge_bytes(b"precommitment", &mut precommitment); | ||
| NoncePrecommitment(precommitment) | ||
| } | ||
|
|
||
| pub fn sum(commitments: &Vec<Self>) -> RistrettoPoint { | ||
| commitments.iter().map(|R_i| R_i.0).sum() | ||
| } | ||
| } | ||
|
|
||
| pub struct Counterparty { | ||
| pubkey: VerificationKey, | ||
| } | ||
|
|
||
| pub struct CounterpartyPrecommitted { | ||
| precommitment: NoncePrecommitment, | ||
| pubkey: VerificationKey, | ||
| } | ||
|
|
||
| pub struct CounterpartyCommitted { | ||
| commitment: NonceCommitment, | ||
| pubkey: VerificationKey, | ||
| } | ||
|
|
||
| impl Counterparty { | ||
| pub fn new(pubkey: VerificationKey) -> Self { | ||
| Counterparty { pubkey } | ||
| } | ||
|
|
||
| pub fn precommit_nonce(self, precommitment: NoncePrecommitment) -> CounterpartyPrecommitted { | ||
| CounterpartyPrecommitted { | ||
| precommitment, | ||
| pubkey: self.pubkey, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl CounterpartyPrecommitted { | ||
| pub fn commit_nonce( | ||
| self, | ||
| commitment: NonceCommitment, | ||
| ) -> Result<CounterpartyCommitted, VMError> { | ||
| // Check H(commitment) =? precommitment | ||
| let received_precommitment = commitment.precommit(); | ||
| let equal = self.precommitment.0.ct_eq(&received_precommitment.0); | ||
| if equal.unwrap_u8() == 0 { | ||
| return Err(VMError::MuSigShareError { | ||
| pubkey: self.pubkey.0.to_bytes(), | ||
| }); | ||
| } | ||
|
|
||
| Ok(CounterpartyCommitted { | ||
| commitment: commitment, | ||
| pubkey: self.pubkey, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl CounterpartyCommitted { | ||
| pub fn sign( | ||
| self, | ||
| share: Scalar, | ||
| challenge: Scalar, | ||
| multikey: &Multikey, | ||
| ) -> Result<Scalar, VMError> { | ||
| // Check if s_i * G == R_i + c * a_i * X_i. | ||
| // s_i = share | ||
| // G = RISTRETTO_BASEPOINT_POINT | ||
| // R_i = self.commitment | ||
| // c = challenge | ||
| // a_i = multikey.factor_for_key(self.pubkey) | ||
| // X_i = self.pubkey | ||
| let S_i = share * RISTRETTO_BASEPOINT_POINT; | ||
| let a_i = multikey.factor_for_key(&self.pubkey); | ||
| let X_i = self.pubkey.0.decompress().ok_or(VMError::InvalidPoint)?; | ||
|
|
||
| if S_i != self.commitment.0 + challenge * a_i * X_i { | ||
| return Err(VMError::MuSigShareError { | ||
| pubkey: self.pubkey.0.to_bytes(), | ||
| }); | ||
| } | ||
|
|
||
| Ok(share) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.