【发布时间】:2021-01-15 15:28:31
【问题描述】:
在 Ethereum Solidity 上,在处理无符号整数余额数时,需要使用一个名为 SafeMath 的特殊库。这是因为integer overflow exploits。
用 Rust 编写的 NEAR 智能合约是否需要类似的缓解措施?还是 Rust 会自动捕获溢出并恐慌?
【问题讨论】:
标签: nearprotocol
在 Ethereum Solidity 上,在处理无符号整数余额数时,需要使用一个名为 SafeMath 的特殊库。这是因为integer overflow exploits。
用 Rust 编写的 NEAR 智能合约是否需要类似的缓解措施?还是 Rust 会自动捕获溢出并恐慌?
【问题讨论】:
标签: nearprotocol
默认情况下,Rust 为调试构建启用溢出检查,但在优化发布构建中禁用。您可以通过在profile.release 部分设置overflow-checks 轻松地在Cargo.toml 中调整它:
[profile.release]
# ...
overflow-checks = true
NEAR 核心合约opt-into the paranoid mode。
即使您选择显式使用saturating_* 或checked_* 方法,仍建议进行额外检查。
【讨论】:
create-near-appgithub.com/near/create-near-app/issues/498的问题报告