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

In funC, 1 != 1 #1022

Open
alan890104 opened this issue Jun 11, 2024 · 2 comments
Open

In funC, 1 != 1 #1022

alan890104 opened this issue Jun 11, 2024 · 2 comments
Labels
FunC Related to FunC compiler to tooling

Comments

@alan890104
Copy link

alan890104 commented Jun 11, 2024

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

image

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.
TON Bugs (1)
TON Bugs (2)

How we solve this problem

We just simply add a division by 1 after the left shift operation, then everything goes correctly.
TON Bugs messageImage new
TON Bugs

Enviroments

We are using @ton/blueprint": "^0.21.0

Hardware Info

MacOS (Macbook M1 pro 2021) built-in SSD.

@EmelyanenkoK
Copy link
Member

Hi! Nice catch. Please contact us in @ton_bugs_bot (check authenticity here: https://github.com/ton-blockchain/bug-bounty) for bounty.

@Netcrepto
Copy link

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

image

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. TON Bugs (1) TON Bugs (2)

How we solve this problem

We just simply add a division by 1 after the left shift operation, then everything goes correctly. TON Bugs messageImage new TON Bugs

Enviroments

We are using @ton/blueprint": "^0.21.0

Hardware Info

MacOS (Macbook M1 pro 2021) built-in SSD.

nice position

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

No branches or pull requests

4 participants