NEAR and safe math on unsigned integers

Deadly 提交于 2021-01-28 08:49:52

问题


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?


回答1:


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 setting overflow-checks in profile.release section:

[profile.release]
# ...
overflow-checks = true

NEAR core contracts opt-into the paranoid mode.

Even if you choose to use saturating_* or checked_* methods explicitly, extra checks are still recommended.



来源:https://stackoverflow.com/questions/64129432/near-and-safe-math-on-unsigned-integers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!