Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(security): DoS in parser (#1239)
* fix(security): DoS in parser Malicious input can cause a denial of service by exponentiating a number to a huge power and taking the CPU for galactic amounts of time, as well as exponentially increasing memory usage. The added test can trigger it before this commit even in release mode. At the time of writing this it's still running after 50' and more than 2700MB. This was found by the fuzzer using the externally reachable parser, even though the test only attacks the culprit here. The cause of this issue is the following: - Recently we added support for scientific notation numbers in the `data` section of an input program; - `NumBigUint` only supports `modpow` when all arguments are `BigUint`; - `FeltBigInt` for primitive-type exponents tried to avoid creating a new `BigUint` as an attempt at optimization, so it used `pow`+`mod_floor` instead; - This combination with a huge exponent means an ever increasing number of allocations. The fix consists in building the `BigUint` and using `modpow` instead. This uses constant space because internally it uses the Montgomery exponentiation algorithm. With this the test finishes in 11ms on my machine. * Leftover `dbg!` * Remove clippy allow
- Loading branch information
e876253
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.add_u64_with_felt/1
3
ns/iter (± 0
)2
ns/iter (± 0
)1.50
add_u64_with_felt/2
3
ns/iter (± 0
)2
ns/iter (± 0
)1.50
add_u64_with_felt/5
2
ns/iter (± 0
)1
ns/iter (± 0
)2
This comment was automatically generated by workflow using github-action-benchmark.
CC: @unbalancedparentheses