Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deocde nonce from be bytes #307

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pallets/signature-bridge/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn generate_maintainer_signatures<T: Config<I>, I: 'static>() -> (Vec<u8>, V
let old_maintainer = ecdsa_generate(DUMMY, None);
let old_maintainer_key = set_maintainer_on_chain::<T, I>(old_maintainer);
let mut message = vec![];
let nonce = 1u32.encode();
let nonce = 1u32.to_be_bytes;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will not compile, it needs to be 1u32.to_be_bytes()

message.extend_from_slice(&nonce);
message.extend_from_slice(&new_maintainer.encode());
let hash = keccak_256(&message);
Expand Down
6 changes: 3 additions & 3 deletions pallets/signature-bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ pub mod pallet {
let maintainer_nonce = MaintainerNonce::<T, I>::get();
let nonce = maintainer_nonce + 1u32.into();
// nonce should be the first 4 bytes of this message
let nonce_from_maintainer = T::MaintainerNonce::decode(&mut &message[..4])
.map_err(|_| Error::<T, I>::InvalidNonce)?;

let mut nonce_bytes = [0u8; 4];
nonce_bytes[0..4].copy_from_slice(&message[..4]);
let nonce_from_maintainer: T::MaintainerNonce = u32::from_be_bytes(nonce_bytes).into();
// Nonce should increment by 1
ensure!(nonce_from_maintainer == nonce, Error::<T, I>::InvalidNonce);

Expand Down
2 changes: 1 addition & 1 deletion pallets/signature-bridge/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn set_maintainer_should_work() {
old_maintainer.try_into().unwrap();
Maintainer::<Test, _>::put(bounded_old_maintainer);
let mut message = vec![];
let nonce = 1u32.encode();
let nonce = 1u32.to_be_bytes();
message.extend_from_slice(&nonce);
message.extend_from_slice(&new_maintainer);
let msg = keccak_256(&message);
Expand Down