Soroban SDK Arithmetic Overflow Vulnerability in Slicing and Random Range Generation Methods
Vulnerability
A vulnerability exists in the Soroban SDK for Rust, specifically in versions up to and including 25.0.1, 23.5.1, and 22.0.8. The issue arises in the `Bytes::slice`, `Vec::slice`, and `Prng::gen_range` (for `u64`) methods, where unchecked arithmetic can lead to overflow. This vulnerability can cause contracts to operate on incorrect data ranges or generate random numbers from unintended ranges, potentially corrupting the contract state. The issue is particularly concerning because the default release profile for Soroban contracts does not enable overflow checks, allowing these errors to go unnoticed. While the SDK's tooling encourages developers to activate overflow checks, many contracts may still be vulnerable by default.
Impact
Exploiting this vulnerability can cause arithmetic operations to silently wrap, leading to incorrect data handling in contracts. For instance, slicing methods may return empty results instead of the expected data, and the random number generation method can produce values from unintended ranges, such as the full range of `u64`, instead of a specified subset.
Reproduction
The vulnerability can be reproduced by creating a Soroban contract that uses the `soroban-sdk` without enabling overflow checks in the release profile. Contracts can then pass user-controlled or computed range bounds that trigger the overflow in the `Bytes::slice`, `Vec::slice`, or `Prng::gen_range` (for `u64`) methods. This can be done by, for example, using `Bound::Excluded(u64::MAX)` or `Bound::Included(u32::MAX)` which would cause the arithmetic to wrap around and produce incorrect results.
Remediation
To address this vulnerability, developers should update to Soroban SDK versions 25.0.2, 23.5.1, or 22.0.9, where the issue has been fixed by replacing unchecked arithmetic with checked operations that prevent overflow. Additionally, contracts should validate range bounds before using them to ensure they do not cause overflow, and workspaces can be configured to enable overflow checks by default.
Vulnerability Rating
Our algorithm analyzes dozens of metrics to generate these 8 key vulnerability categories, which are then combined to calculate the overall risk score.
