[Bug] Addition overflow panics when trying to trim
(in sonic_pc) with a supported_degree
or a supported_hiding_bound
too large
#2166
Labels
bug
Something isn't working
Addition overflow panics when trying to
trim
(in sonic_pc) with asupported_degree
or asupported_hiding_bound
too largeWe (@FuzzingLabs) found 3 additions with overflow in the trim function, making the library crash when compiled in debug and silently overflow when compiled in release mode (which might lead to undefined behavior).
thread 'main' panicked at /home/ronan/Desktop/Projects/ALEO/snarkVM/algorithms/src/polycommit/sonic_pc/mod.rs:121:55
thread 'main' panicked at /home/ronan/Desktop/Projects/ALEO/snarkVM/algorithms/src/polycommit/sonic_pc/mod.rs:122:49
thread 'main' panicked at /home/ronan/Desktop/Projects/ALEO/snarkVM/algorithms/src/polycommit/sonic_pc/mod.rs:104:34:
Your Environment
Steps to reproduce
Download:
Testing program:
main.rs:
Cargo.toml:
Build and run:
Root causes
https://github.com/AleoHQ/snarkVM/blob/6528130cd63920eb85f09a7a6a1ab15cdc559362/algorithms/src/polycommit/sonic_pc/mod.rs#L121
https://github.com/AleoHQ/snarkVM/blob/6528130cd63920eb85f09a7a6a1ab15cdc559362/algorithms/src/polycommit/sonic_pc/mod.rs#L122
https://github.com/AleoHQ/snarkVM/blob/6528130cd63920eb85f09a7a6a1ab15cdc559362/algorithms/src/polycommit/sonic_pc/mod.rs#L104
Detailed behavior (RUST_BACKTRACE=1)
In the snarkVM implementation
The
trim
function is only used in thebatch_circuit_setup
function in varuna. Thesupported_hiding_bound
parameter is set to 1 (l.91), so it cannot overflow. Thesupported_degree
parameter is set toindexed_circuit.max_degree()
(l.95), which can be only worth an even value (and so<usize_max
), or an odd value that is to small to overflow (regarding the ouput of themax_degree
function). So the overflow can not occur with current usage.Solving possibilities
Replace the additions to lines 104, 121, 122 by a checked-add, and check that the result is not
None
.The text was updated successfully, but these errors were encountered: