Files
powdr/executor
ShuangWu121 b13d5e857e fix mersenne31 overflow (#1868)
when run this command: 
`cargo run pil test_data/asm/book/hello_world.asm --inputs 0 -o output
--field m31 --prove-with plonky3 -f`
it gets error: 
```
thread 'main' panicked at 
powdr/executor/src/witgen/global_constraints.rs:195:37:
attempt to subtract with overflow
```

The problem is in function
```

fn smallest_period_candidate<T: FieldElement>(fixed: &[T]) -> Option<u64> {
    if fixed.first() != Some(&0.into()) {
        return None;
    }

    (1..63).find(|bit| fixed.last() == Some(&((1u64 << bit) - 1).into()))
}
```
when using Mersenne31 field (prime: 2^31 -1) and the last element of
fixed is 0, it is equivalent to 2^31-1, then the function return bit=31

and bit=31 overflow at this line:
`let mask = T::Integer::from(((1 << bit) - 1) as u64);`
in function process_fixed_column, as 1 is by default to be i32

so I add the code below to handle the special case and make 1 to be 1u64

`if fixed.last() == Some(&0.into()) {
        return None; 
    }`

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2024-10-03 14:51:46 +00:00
..
2024-10-03 14:51:46 +00:00
2024-09-23 14:44:04 +00:00