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

Experimental power number generator for uints #892

Merged
merged 9 commits into from
Apr 11, 2023
Merged

Conversation

ggrieco-tob
Copy link
Member

@ggrieco-tob ggrieco-tob commented Jan 5, 2023

This should be considered experimental until we know it works better

@rappie
Copy link

rappie commented Jan 6, 2023

I have run some tests. It does not seem to be working.

I would expect echidna to be able to break testAmount without the helper. It needs a number between 1e16 and 1e20, which should occur frequently now in the distribution of the random numbers.

pragma solidity ^0.8.0;

contract EchidnaTest {
    uint256 private constant min = 16;
    uint256 private constant max = 20;

    function helper(uint256 amount) public {
        amount = (10**min) + (amount % ((10**max) - (10**min)));
        testAmount(amount);
    }

    function testAmount(uint256 amount) public {
        if (amount > (10**min) && amount < (10**max)) {
            assert(false);
        }
    }
}
testMode: assertion
testLimit: 100000

@ggrieco-tob
Copy link
Member Author

This is working now, thanks @rappie !

@ggrieco-tob ggrieco-tob marked this pull request as ready for review January 6, 2023 21:25
@rappie
Copy link

rappie commented Jan 31, 2023

I have tested this.

As expected, it is noticably slower to break certain properties than before, but it does manage to break them without helpers.

Personally I'd prefer to have only the logarithmic RNG. I believe this to be superior for fuzzing, but then again I'm no expert :)

[ (getRandomR (0, 1023), 1)
, (getRandomR (0, 2 ^ n - 5), 8)
, (getRandomR (2 ^ n - 5, 2 ^ n - 1), 1)
, (getRandomPow (n - 5), 4)
Copy link
Member

Choose a reason for hiding this comment

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

as I understand the chance of this happening will be 4/14 ~ 28%?

@ggrieco-tob ggrieco-tob merged commit 558baef into master Apr 11, 2023
7 checks passed
@ggrieco-tob ggrieco-tob deleted the dev-power-gen branch April 11, 2023 17:37
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.

None yet

3 participants