未经检查的低级调用
未经检查的低级调用在智能合约开发中是常见的漏洞来源。 这些调用包括call()
,delegatecall()
,staticcall()
和 send()
,当它们失败时不会回滚交易,而是返回布尔值false
。 未检查这些返回值可能导致严重的安全问题。
The send()
function in Ethereum is notoriously unreliable for transferring ether due to its strict gas limit of 2300. 这意味着如果接收地址的回退函数需要的气体超过此限额,send()
操作将不会成功。 如果不正确地管理这个限制,可能会导致严重的漏洞。
一个著名的例子是2016年臭名昭著的"King of Ether" 游戏。 该游戏的设计是将支付最多的玩家加冕为“国王”,并将头衔和相关的以太币转移到每个新的最高支付者。 然而,由于send()
函数的限制,当接收者的回退函数需要超过2300燃气时,合约未能正确地转移以太币。 As a result, some participants did not receive their due payments, leading to significant financial losses. 这一事件凸显了在智能合约中谨慎处理以太币交易的重要性。
For an in-depth analysis of what went wrong and the lessons learned, you can review the detailed King of Ether postmortem.