Skip to content

Commit

Permalink
fix(minor-multisig-prover): include stellar signers with no signatures (
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Oct 7, 2024
1 parent dd25645 commit 7191c65
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
22 changes: 17 additions & 5 deletions contracts/multisig-prover/src/encoding/stellar_xdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,19 +212,19 @@ mod tests {
"addr_1",
"12f7d9a9463212335914b39ee90bfa2045f90b64c1f2d7b58ed335282abac4a4",
8u128,
"b5b3b0749aa585f866d802e32ca4a6356f82eb52e2a1b4797cbaa30f3d755462f2eb995c70d9099e436b8a48498e4d613ff2d3ca7618973a36c2fde17493180f",
Some("b5b3b0749aa585f866d802e32ca4a6356f82eb52e2a1b4797cbaa30f3d755462f2eb995c70d9099e436b8a48498e4d613ff2d3ca7618973a36c2fde17493180f"),
),
(
"addr_2",
"4c3863e4b0252a8674c1c6ad70b3ca3002b400b49ddfae5583b21907e65c5dd8",
1u128,
"cb8a1b98ec7678d5eb965d47c449b2b8396d170e53ad7b5f65a7c0fdf2aebe206b65be7cb2e81c7ddd8924acb2ffc2d463b678993227fdfbfc3ef03a8ffa030c",
None
),
(
"addr_3",
"c35aa94d2038f258ecb1bb28fbc8a83ab79d2dc0a7223fd528a8f52a14c03292",
7u128,
"28e2c8accfa1c2db93349c6d3f783004d6a92cdbf322b92b3555315999e0eaf5d8bdf9deb58d798168a880972e81b8513dcb942de44862317d501cf7445c660a"
Some("28e2c8accfa1c2db93349c6d3f783004d6a92cdbf322b92b3555315999e0eaf5d8bdf9deb58d798168a880972e81b8513dcb942de44862317d501cf7445c660a")
),

];
Expand Down Expand Up @@ -274,7 +274,13 @@ mod tests {
"addr_1",
"77dd4768dda195f8080fe970be8fec5fee9cea781718158ce19d4a331442fd57",
2u128,
"91db8ad94ab379ee9021caeb3ee852582d09d06801213256cbd2937f2ad8182f518fde7a7f8c801adde7161e05cbbb9841ac0bf3290831570a54c6ae3d089703",
Some("91db8ad94ab379ee9021caeb3ee852582d09d06801213256cbd2937f2ad8182f518fde7a7f8c801adde7161e05cbbb9841ac0bf3290831570a54c6ae3d089703"),
),
(
"addr_2",
"c35aa94d2038f258ecb1bb28fbc8a83ab79d2dc0a7223fd528a8f52a14c03292",
1u128,
None,
),
];

Expand Down Expand Up @@ -353,9 +359,15 @@ mod tests {
created_at,
}
}
fn gen_signers_with_sig(signers_data: Vec<(&str, &str, u128, &str)>) -> Vec<SignerWithSig> {

fn gen_signers_with_sig(
signers_data: Vec<(&str, &str, u128, Option<&str>)>,
) -> Vec<SignerWithSig> {
signers_data
.into_iter()
.filter_map(|(addr, pub_key, weight, sig)| {
sig.map(|signature| (addr, pub_key, weight, signature))
})
.map(|(addr, pub_key, weight, sig)| {
Signer {
address: Addr::unchecked(addr),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0000001000000001000000020000001000000001000000010000001100000001000000050000000f00000010636f6e74726163745f61646472657373000000120000000100000000000000000000000000000000000000000000000000000000000000060000000f0000000a6d6573736167655f696400000000000e00000004746573740000000f0000000c7061796c6f61645f686173680000000d00000020595c9108df17d1cc43e8268ec1516064299c1388bcc86fdd566bcdf400a0a1ed0000000f0000000e736f757263655f6164647265737300000000000e0000003843414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141484b334d0000000f0000000c736f757263655f636861696e0000000e00000006736f7572636500000000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000030000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d00000040b5b3b0749aa585f866d802e32ca4a6356f82eb52e2a1b4797cbaa30f3d755462f2eb995c70d9099e436b8a48498e4d613ff2d3ca7618973a36c2fde17493180f0000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d0000002012f7d9a9463212335914b39ee90bfa2045f90b64c1f2d7b58ed335282abac4a40000000f00000006776569676874000000000009000000000000000000000000000000080000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d00000040cb8a1b98ec7678d5eb965d47c449b2b8396d170e53ad7b5f65a7c0fdf2aebe206b65be7cb2e81c7ddd8924acb2ffc2d463b678993227fdfbfc3ef03a8ffa030c0000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d000000204c3863e4b0252a8674c1c6ad70b3ca3002b400b49ddfae5583b21907e65c5dd80000000f00000006776569676874000000000009000000000000000000000000000000010000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d0000004028e2c8accfa1c2db93349c6d3f783004d6a92cdbf322b92b3555315999e0eaf5d8bdf9deb58d798168a880972e81b8513dcb942de44862317d501cf7445c660a0000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d00000020c35aa94d2038f258ecb1bb28fbc8a83ab79d2dc0a7223fd528a8f52a14c032920000000f00000006776569676874000000000009000000000000000000000000000000070000000f000000097468726573686f6c64000000000000090000000000000000000000000000000a
0000001000000001000000020000001000000001000000010000001100000001000000050000000f00000010636f6e74726163745f61646472657373000000120000000100000000000000000000000000000000000000000000000000000000000000060000000f0000000a6d6573736167655f696400000000000e00000004746573740000000f0000000c7061796c6f61645f686173680000000d00000020595c9108df17d1cc43e8268ec1516064299c1388bcc86fdd566bcdf400a0a1ed0000000f0000000e736f757263655f6164647265737300000000000e0000003843414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141484b334d0000000f0000000c736f757263655f636861696e0000000e00000006736f7572636500000000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000030000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d00000040b5b3b0749aa585f866d802e32ca4a6356f82eb52e2a1b4797cbaa30f3d755462f2eb995c70d9099e436b8a48498e4d613ff2d3ca7618973a36c2fde17493180f0000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d0000002012f7d9a9463212335914b39ee90bfa2045f90b64c1f2d7b58ed335282abac4a40000000f00000006776569676874000000000009000000000000000000000000000000080000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000010000000f00000008556e7369676e65640000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d000000204c3863e4b0252a8674c1c6ad70b3ca3002b400b49ddfae5583b21907e65c5dd80000000f00000006776569676874000000000009000000000000000000000000000000010000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d0000004028e2c8accfa1c2db93349c6d3f783004d6a92cdbf322b92b3555315999e0eaf5d8bdf9deb58d798168a880972e81b8513dcb942de44862317d501cf7445c660a0000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d00000020c35aa94d2038f258ecb1bb28fbc8a83ab79d2dc0a7223fd528a8f52a14c032920000000f00000006776569676874000000000009000000000000000000000000000000070000000f000000097468726573686f6c64000000000000090000000000000000000000000000000a
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0000001000000001000000020000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000050000001100000001000000020000000f000000067369676e657200000000000d00000020358a2305fc783b6072049ee6f5f76fb14c3a14d7c01e36d9ef502661bf46a0110000000f00000006776569676874000000000009000000000000000000000000000000090000001100000001000000020000000f000000067369676e657200000000000d000000203b1caf530189a9a65ae347b18cb8bf88729ba90d2aeaf7f185b600400ab498910000000f00000006776569676874000000000009000000000000000000000000000000010000001100000001000000020000000f000000067369676e657200000000000d00000020531616448afd45c0e3e053622cbccb65d8fc99cd2f02636d728739811e72eafb0000000f00000006776569676874000000000009000000000000000000000000000000030000001100000001000000020000000f000000067369676e657200000000000d000000205e4c8ec6569774adf69cb6e2bc4ef556c2fc6b412c85d6a5e0b18d54b069e5940000000f00000006776569676874000000000009000000000000000000000000000000070000001100000001000000020000000f000000067369676e657200000000000d000000208097528d987899f887c08c23a928dfe6fe9550010d19c7be0b46b5d0596997cc0000000f00000006776569676874000000000009000000000000000000000000000000030000000f000000097468726573686f6c6400000000000009000000000000000000000000000000110000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000010000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d0000004091db8ad94ab379ee9021caeb3ee852582d09d06801213256cbd2937f2ad8182f518fde7a7f8c801adde7161e05cbbb9841ac0bf3290831570a54c6ae3d0897030000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d0000002077dd4768dda195f8080fe970be8fec5fee9cea781718158ce19d4a331442fd570000000f00000006776569676874000000000009000000000000000000000000000000020000000f000000097468726573686f6c640000000000000900000000000000000000000000000001
0000001000000001000000020000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000050000001100000001000000020000000f000000067369676e657200000000000d00000020358a2305fc783b6072049ee6f5f76fb14c3a14d7c01e36d9ef502661bf46a0110000000f00000006776569676874000000000009000000000000000000000000000000090000001100000001000000020000000f000000067369676e657200000000000d000000203b1caf530189a9a65ae347b18cb8bf88729ba90d2aeaf7f185b600400ab498910000000f00000006776569676874000000000009000000000000000000000000000000010000001100000001000000020000000f000000067369676e657200000000000d00000020531616448afd45c0e3e053622cbccb65d8fc99cd2f02636d728739811e72eafb0000000f00000006776569676874000000000009000000000000000000000000000000030000001100000001000000020000000f000000067369676e657200000000000d000000205e4c8ec6569774adf69cb6e2bc4ef556c2fc6b412c85d6a5e0b18d54b069e5940000000f00000006776569676874000000000009000000000000000000000000000000070000001100000001000000020000000f000000067369676e657200000000000d000000208097528d987899f887c08c23a928dfe6fe9550010d19c7be0b46b5d0596997cc0000000f00000006776569676874000000000009000000000000000000000000000000030000000f000000097468726573686f6c6400000000000009000000000000000000000000000000110000001100000001000000030000000f000000056e6f6e63650000000000000d0000002000000000000000000000000000000000000000000000000000000000000007e80000000f000000077369676e657273000000001000000001000000020000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000020000000f000000065369676e656400000000000d0000004091db8ad94ab379ee9021caeb3ee852582d09d06801213256cbd2937f2ad8182f518fde7a7f8c801adde7161e05cbbb9841ac0bf3290831570a54c6ae3d0897030000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d0000002077dd4768dda195f8080fe970be8fec5fee9cea781718158ce19d4a331442fd570000000f00000006776569676874000000000009000000000000000000000000000000020000001100000001000000020000000f000000097369676e61747572650000000000001000000001000000010000000f00000008556e7369676e65640000000f000000067369676e657200000000001100000001000000020000000f000000067369676e657200000000000d00000020c35aa94d2038f258ecb1bb28fbc8a83ab79d2dc0a7223fd528a8f52a14c032920000000f00000006776569676874000000000009000000000000000000000000000000010000000f000000097468726573686f6c640000000000000900000000000000000000000000000001
2 changes: 1 addition & 1 deletion contracts/multisig/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl TryFrom<HexBinary> for Recoverable {
}

#[cw_serde]
#[derive(Ord, PartialOrd, Eq)]
#[derive(Ord, PartialOrd, Eq, Hash)]
pub enum PublicKey {
/// ECDSA public key must be in compressed format (33 bytes)
#[serde(deserialize_with = "deserialize_ecdsa_key")]
Expand Down
55 changes: 35 additions & 20 deletions external-gateways/stellar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
pub mod error;

use std::collections::HashMap;
use std::str::FromStr;

use axelar_wasm_std::utils::TryMapExt;
use cosmwasm_std::Uint256;
use error_stack::{bail, Report, ResultExt};
use multisig::key::PublicKey;
use multisig::key::Signature::Ed25519;
use multisig::msg::SignerWithSig;
use multisig::key::{PublicKey, Signature};
use multisig::msg::{Signer, SignerWithSig};
use multisig::verifier_set::VerifierSet;
use sha3::{Digest, Keccak256};
use stellar_strkey::Contract;
Expand Down Expand Up @@ -277,20 +278,20 @@ impl TryFrom<ProofSigner> for ScVal {
}
}

impl TryFrom<SignerWithSig> for ProofSigner {
impl TryFrom<(Signer, Option<Signature>)> for ProofSigner {
type Error = Report<Error>;

fn try_from(value: SignerWithSig) -> Result<Self, Self::Error> {
fn try_from((signer, signature): (Signer, Option<Signature>)) -> Result<Self, Self::Error> {
let signer = WeightedSigner {
signer: BytesM::try_from(value.signer.pub_key.as_ref())
.change_context(InvalidPublicKey)?,
weight: value.signer.weight.into(),
signer: BytesM::try_from(signer.pub_key.as_ref()).change_context(InvalidPublicKey)?,
weight: signer.weight.into(),
};

let signature = match value.signature {
Ed25519(signature) => ProofSignature::Signed(
let signature = match signature {
Some(Ed25519(signature)) => ProofSignature::Signed(
BytesM::try_from(signature.to_vec()).change_context(InvalidSignature)?,
),
None => ProofSignature::Unsigned,
_ => bail!(Error::UnsupportedSignature),
};

Expand Down Expand Up @@ -326,12 +327,24 @@ impl TryFrom<(VerifierSet, Vec<SignerWithSig>)> for Proof {
type Error = Report<Error>;

fn try_from(
(verifier_set, mut signers): (VerifierSet, Vec<SignerWithSig>),
(verifier_set, signers): (VerifierSet, Vec<SignerWithSig>),
) -> Result<Self, Self::Error> {
signers.sort_by(|signer1, signer2| signer1.signer.pub_key.cmp(&signer2.signer.pub_key));
let mut signatures_by_pub_keys: HashMap<_, _> = signers
.into_iter()
.map(|signer| (signer.signer.pub_key.clone(), signer.signature))
.collect();

let mut sorted_verifiers = verifier_set.signers.into_iter().collect::<Vec<_>>();

let signers = signers
sorted_verifiers
.sort_by(|(_, signer1), (_, signer2)| signer1.pub_key.cmp(&signer2.pub_key));

let signers = sorted_verifiers
.into_iter()
.map(|(_, signer)| {
let signature = signatures_by_pub_keys.remove(&signer.pub_key);
(signer, signature)
})
.map(TryInto::try_into)
.collect::<Result<Vec<_>, _>>()?;

Expand Down Expand Up @@ -520,17 +533,19 @@ mod test {
#[test]
fn proof_encode() {
let signers = vec![
("56ab9b9fa21dc37d77d093ba8d0a954ee4af43fb701e93751352876c78e9d950", 8, "ad2e9cf32faf4f004e7005b7a0959c65882ce66279e46f6bcd3c231e88381bb7c0b54378ec31c526af770d0abf3965c790e8b850c34521f8565eb467110d1505"),
("6ca711b4a5dec4c05f93ec6c61bce0b2a624f5dae358a5801b02a10404997918",2,"2abbbfe5d730e8c72c0393c465c9e34c45c5745e0d72fc817cacaa2ecfd4cf00d4751e9853cac9ded1afb17d00316382fde62db962a628893e6f28985a3b3c00"),
("cf26fe65ca2c10ed3977d941e7f592793397bc33e549e381117bd6a199b983c7",8,"c5c268c3b4ecd78984fe4579f8e421eefbea19b1a2310c5fe43f45fb338c023f808b2bd44d766b840fe5297e711f06a8a2ae7a74094a0b6abc2c92aa7a234409"),
("fd65bd8136a40785b413624070c19677a4d42f9227c0c41624b5c63f58400668", 4, "c4c68ecb792f0b0509214f31ed986dad776d4f6813a0f5318c32eb14e20774a54849f4427ba1e826db3e7c39c8afb560a182ecebdb51eb41e425bd3e1cb57b08"),
("fe571761ad0a9834027e11e6c0a5166972054fbdd7452566e9c31f271f6caad9", 9,"0af1cc063353d57f3722ba93e021dc23e3498735affa2a65638bd7926f9290006df8643f75ff55c5ef55b38647464280680d5d699b588392c0188a9337afea03")
].iter().map(|(signer, weight, signature)| ProofSigner {
("39f771f3bd457def6c426d72c0ea3be8cacaf886845cc5eee821fb51f9af08a4", 3, None),
("56ab9b9fa21dc37d77d093ba8d0a954ee4af43fb701e93751352876c78e9d950", 8, Some("ad2e9cf32faf4f004e7005b7a0959c65882ce66279e46f6bcd3c231e88381bb7c0b54378ec31c526af770d0abf3965c790e8b850c34521f8565eb467110d1505")),
("6ca711b4a5dec4c05f93ec6c61bce0b2a624f5dae358a5801b02a10404997918", 2, Some("2abbbfe5d730e8c72c0393c465c9e34c45c5745e0d72fc817cacaa2ecfd4cf00d4751e9853cac9ded1afb17d00316382fde62db962a628893e6f28985a3b3c00")),
("cf26fe65ca2c10ed3977d941e7f592793397bc33e549e381117bd6a199b983c7", 8, Some("c5c268c3b4ecd78984fe4579f8e421eefbea19b1a2310c5fe43f45fb338c023f808b2bd44d766b840fe5297e711f06a8a2ae7a74094a0b6abc2c92aa7a234409")),
("fbb4b870e800038f1379697fae3058938c59b696f38dd0fdf2659c0cf3a5b663", 1, None),
("fd65bd8136a40785b413624070c19677a4d42f9227c0c41624b5c63f58400668", 4, Some("c4c68ecb792f0b0509214f31ed986dad776d4f6813a0f5318c32eb14e20774a54849f4427ba1e826db3e7c39c8afb560a182ecebdb51eb41e425bd3e1cb57b08")),
("fe571761ad0a9834027e11e6c0a5166972054fbdd7452566e9c31f271f6caad9", 9, Some("0af1cc063353d57f3722ba93e021dc23e3498735affa2a65638bd7926f9290006df8643f75ff55c5ef55b38647464280680d5d699b588392c0188a9337afea03")),
].into_iter().map(|(signer, weight, signature)| ProofSigner {
signer: WeightedSigner {
signer: signer.parse().unwrap(),
weight: *weight,
weight,
},
signature: ProofSignature::Signed(signature.parse().unwrap()),
signature: match signature { Some(signature) => ProofSignature::Signed(signature.parse().unwrap()), None => ProofSignature::Unsigned },
}).collect();

let proof = Proof {
Expand Down
Loading

0 comments on commit 7191c65

Please sign in to comment.