You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ipromise2324 and I are building merkle distributor with bitmap implementation, but we find left shift operator will cause problem as it return unexpected value.
Description
When we call the is_claimed function with the index parameter set to 0, the claim_bit_index is calculated as 0 % 256, which results in claim_bit_index = 0. Consequently, int mask = 1 << 0, meaning mask = 1.
As we start using the mask variable for some comparisons, we notice an interesting situation. The mask currently equals 1, but when we compare it with mask == 1, the result dumped is 0, which is not what we expected. It should be -1, because mask = 1 and 1 == 1. Then, when we compare mask != 1, the dumped result turns out to be -1, which is also contrary to common logic.
How we solve this problem
We just simply add a division by 1 after the left shift operation, then everything goes correctly.
Enviroments
We are using @ton/blueprint": "^0.21.0
Hardware Info
MacOS (Macbook M1 pro 2021) built-in SSD.
The text was updated successfully, but these errors were encountered:
@ipromise2324 and I are building merkle distributor with bitmap implementation, but we find left shift operator will cause problem as it return unexpected value.
Description
When we call the is_claimed function with the index parameter set to 0, the claim_bit_index is calculated as 0 % 256, which results in claim_bit_index = 0. Consequently, int mask = 1 << 0, meaning mask = 1.
As we start using the mask variable for some comparisons, we notice an interesting situation. The mask currently equals 1, but when we compare it with mask == 1, the result dumped is 0, which is not what we expected. It should be -1, because mask = 1 and 1 == 1. Then, when we compare mask != 1, the dumped result turns out to be -1, which is also contrary to common logic.
How we solve this problem
We just simply add a division by 1 after the left shift operation, then everything goes correctly.
Background
@ipromise2324 and I are building merkle distributor with bitmap implementation, but we find left shift operator will cause problem as it return unexpected value.
Description
When we call the
is_claimed
function with theindex
parameter set to 0, theclaim_bit_index
is calculated as0 % 256
, which results inclaim_bit_index = 0
. Consequently,int mask = 1 << 0
, meaningmask = 1
.As we start using the
mask
variable for some comparisons, we notice an interesting situation. Themask
currently equals 1, but when we compare it withmask == 1
, the result dumped is 0, which is not what we expected. It should be -1, becausemask = 1
and1 == 1
. Then, when we comparemask != 1
, the dumped result turns out to be -1, which is also contrary to common logic.How we solve this problem
We just simply add a
division by 1
after the left shift operation, then everything goes correctly.Enviroments
We are using
@ton/blueprint": "^0.21.0
Hardware Info
MacOS (Macbook M1 pro 2021) built-in SSD.
The text was updated successfully, but these errors were encountered: