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

Deocde nonce from be bytes #307

merged 1 commit into from
Mar 20, 2023

Conversation

salman01zp
Copy link
Contributor

@salman01zp salman01zp commented Mar 20, 2023

Summary of changes

  • Decoder from parity_scale_codec expects nonce to be decoded from le_bytes, whereas dkg signs a message in which nonce is converted to be_bytes.
let nonce_from_maintainer = T::MaintainerNonce::decode(&mut &message[..4])
.map_err(|_| Error::<T, I>::InvalidNonce)?;

Therefore, we need to decode nonce directly using from_be_bytes

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();

Reference issue to close (if applicable)

Closes

@salman01zp salman01zp requested review from 1xstj and shekohex March 20, 2023 07:38
@salman01zp salman01zp marked this pull request as ready for review March 20, 2023 07:38
@salman01zp salman01zp requested a review from drewstone March 20, 2023 07:39
@drewstone drewstone merged commit 9f21025 into main Mar 20, 2023
@drewstone drewstone deleted the salman/decode_nonce branch March 20, 2023 08:06
@drewstone
Copy link
Contributor

Great catch @salman01zp

@@ -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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants