Skip to content

Commit

Permalink
Update signers hash for multiversx after contracts audit.
Browse files Browse the repository at this point in the history
  • Loading branch information
raress96 committed Nov 20, 2024
1 parent 25c3edf commit fbf1321
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
20 changes: 15 additions & 5 deletions ampd/src/mvx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use cosmwasm_std::Uint256;
use multisig::key::PublicKey;
use multisig::msg::Signer;
use multisig::verifier_set::VerifierSet;
use num_traits::ToBytes;
use sha3::{Digest, Keccak256};

use crate::mvx::error::Error;
Expand All @@ -24,15 +25,20 @@ pub struct WeightedSigners {

impl WeightedSigners {
pub fn hash(&self) -> Hash {
let mut encoded = Vec::new();
let mut encoded: Vec<Vec<u8>> = Vec::new();

encoded.push(usize_to_u32(self.signers.len()));

for signer in self.signers.iter() {
encoded.push(signer.signer.as_slice());
encoded.push(signer.weight.as_slice());
encoded.push(signer.signer.to_vec());

encoded.push(usize_to_u32(signer.weight.len()));
encoded.push(signer.weight.to_vec());
}

encoded.push(self.threshold.as_slice());
encoded.push(self.nonce.as_slice());
encoded.push(usize_to_u32(self.threshold.len()));
encoded.push(self.threshold.to_vec());
encoded.push(self.nonce.to_vec());

Keccak256::digest(encoded.concat()).into()
}
Expand Down Expand Up @@ -76,6 +82,10 @@ fn uint256_to_compact_vec(value: Uint256) -> Vec<u8> {
bytes[slice_from..].to_vec()
}

fn usize_to_u32(value: usize) -> Vec<u8> {
(value as u32).to_be_bytes().to_vec()
}

pub fn ed25519_key(pub_key: &PublicKey) -> Result<[u8; 32], Error> {
return match pub_key {
PublicKey::Ed25519(ed25519_key) => Ok(<[u8; 32]>::try_from(ed25519_key.as_ref())
Expand Down
3 changes: 2 additions & 1 deletion ampd/src/mvx/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,9 @@ mod tests {
// 0000000000000000000000000000000000000000000000000000000000000005 - the nonce (created_at date as uint256)
let data = HexBinary::from_hex("0000000345e67eaf446e6c26eb3a2b55b64339ecf3a4d1d03180bee20eb5afdd23fa644f0000000101c387253d29085a8036d6ae2cafb1b14699751417c0ce302cfe03da279e6b5c040000000101dd9822c7fa239dda9913ebee813ecbe69e35d88ff651548d5cc42c033a8a667b000000010100000001020000000000000000000000000000000000000000000000000000000000000005")
.unwrap();
// This hash is generated externally using the MultiversX Gateway contract and is 100% correct
let signers_hash =
HexBinary::from_hex("29f81aa379fa1f5973d05dd25e5ae4bc1afa2aa30156b1db5ec437a46ba4fd28")
HexBinary::from_hex("ad334409a09406b82c1d0f86bdc0aa8f68950c996643c884e6be66e6ea821654")
.unwrap();

let wrong_event = Events {
Expand Down

0 comments on commit fbf1321

Please sign in to comment.