On Ethereum Solidity, a special library called SafeMath
needs to be used when dealing with unsigned integer balance number. This is because of the integer overflow exploits.
Does NEAR smart contracts written in Rust need similar mitigations? Or does Rust trap the oveflow automatically and panic?
By default, Rust has overflow checks enabled for debug builds, but disabled in optimized release builds. You can easily tweak it in
Cargo.toml
by settingoverflow-checks
inprofile.release
section:NEAR core contracts opt-into the paranoid mode.
Even if you choose to use
saturating_*
orchecked_*
methods explicitly, extra checks are still recommended.