Skip to content

Commit

Permalink
chore: use updated u128 rkvy
Browse files Browse the repository at this point in the history
Signed-off-by: Guilherme Felipe da Silva <[email protected]>
  • Loading branch information
frenzox committed Aug 12, 2024
1 parent 4304101 commit 540d5b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
11 changes: 6 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 6 additions & 18 deletions contracts/multisig-prover/src/encoding/rkyv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ pub fn encode(
.map(|x| to_weighted_signature(x, &payload_hash))
.transpose()?
.unwrap_or_else(|| {
let weight =
axelar_rkyv_encoding::types::U256::from_le(to_u256_le(signer.weight.u128()));
let weight = axelar_rkyv_encoding::types::U128::from(signer.weight.u128());
(
pubkey,
axelar_rkyv_encoding::types::WeightedSigner::new(None, weight),
Expand All @@ -40,9 +39,7 @@ pub fn encode(
signers_with_signatures.push(signature_found);
}
let created_at = verifier_set.created_at;
let threshold = axelar_rkyv_encoding::types::U256::from_le(crate::encoding::rkyv::to_u256_le(
verifier_set.threshold.u128(),
));
let threshold = axelar_rkyv_encoding::types::U128::from(verifier_set.threshold.u128());
let bytes = axelar_rkyv_encoding::encode::<1024>(
// Todo reason about this "1024" magic number.
created_at,
Expand All @@ -57,15 +54,14 @@ pub fn encode(
pub fn to_verifier_set(vs: &VerifierSet) -> Result<axelar_rkyv_encoding::types::VerifierSet> {
let mut signers: BTreeMap<
axelar_rkyv_encoding::types::PublicKey,
axelar_rkyv_encoding::types::U256,
axelar_rkyv_encoding::types::U128,
> = BTreeMap::new();

vs.signers
.iter()
.try_for_each(|(_, signer)| -> Result<()> {
let enc_pubkey = to_pub_key(&signer.pub_key)?;
let enc_weight =
axelar_rkyv_encoding::types::U256::from_le(to_u256_le(signer.weight.u128()));
let enc_weight = axelar_rkyv_encoding::types::U128::from(signer.weight.u128());

signers.insert(enc_pubkey, enc_weight);
Ok(())
Expand All @@ -74,7 +70,7 @@ pub fn to_verifier_set(vs: &VerifierSet) -> Result<axelar_rkyv_encoding::types::
Ok(axelar_rkyv_encoding::types::VerifierSet::new(
vs.created_at,
signers,
axelar_rkyv_encoding::types::U256::from_le(to_u256_le(vs.threshold.u128())),
axelar_rkyv_encoding::types::U128::from(vs.threshold.u128()),
))
}

Expand All @@ -89,13 +85,6 @@ fn to_pub_key(pk: &PublicKey) -> Result<axelar_rkyv_encoding::types::PublicKey>
})
}

// Fits a u128 into a u256 in little endian representation.
fn to_u256_le(u: u128) -> [u8; 32] {
let mut uin256 = [0u8; 32];
uin256[0..16].copy_from_slice(&u.to_le_bytes());
uin256
}

impl TryFrom<&Payload> for axelar_rkyv_encoding::types::Payload {
type Error = ContractError;
fn try_from(value: &Payload) -> std::result::Result<Self, Self::Error> {
Expand Down Expand Up @@ -134,8 +123,7 @@ pub fn to_weighted_signature(
)> {
let enc_pub_key = to_pub_key(&sig.signer.pub_key)?;
let enc_signature = to_signature(&sig.signature, &sig.signer.pub_key, payload_hash)?;
let enc_weight =
axelar_rkyv_encoding::types::U256::from_le(to_u256_le(sig.signer.weight.u128()));
let enc_weight = axelar_rkyv_encoding::types::U128::from(sig.signer.weight.u128());

Ok((
enc_pub_key,
Expand Down

0 comments on commit 540d5b4

Please sign in to comment.