Add assert to ensure unused bits in 32 byte address are zero#2
Open
eranrund wants to merge 1 commit into
Open
Conversation
eranrund
commented
Feb 26, 2026
| for i in 0u8..253u8 { | ||
| sliced_bits[i] = address_bits[i]; | ||
| } | ||
| assert_eq(address_bytes[31] & 0xE0, 0u8); |
Author
There was a problem hiding this comment.
0xE0 corresponds to the bit pattern 1110 0000. We use it to check the three most significant bits of the last byte and ensure they are zero.
To verify that this works as expected, I wrote the following test transition:
transition test(addr: [u8; 32]) -> ([bool; 256], u8) {
let bits = Serialize::to_bits_raw(addr);
return (bits, addr[31] & 0xE0);
}
I then ran it with:
leo run mint_debug.aleo/test '[255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,255u8,31u8]'
Note that the final byte is 31, which in binary is 0001 1111.
This means its three most significant bits are zero.
The result was:
[true, true, ..., true, false, false, false], 0
This confirms that the address [255, 255, ..., 31] sets the first 253 bits to true, while the last three bits remain false. These last three bits are the unused bits we want to ensure are zero, and the mask addr[31] & 0xE0 returning 0 confirms that condition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.