我是一名使用 Solidity 和区块链技术的新手,我正在阅读一些好的实践来改进我的代码。
我有一个关于我不太了解的代码的问题:
来源:https ://github.com/ConsenSys/smart-contract-best-practices/blob/master/docs/known_attacks.md
// INSECURE
mapping (address => uint) private userBalances;
function withdrawBalance() public {
uint amountToWithdraw = userBalances[msg.sender];
require(msg.sender.call.value(amountToWithdraw)()); // At this point, the caller's code is executed, and can call withdrawBalance again
userBalances[msg.sender] = 0;
}
在上面的代码中被认为是不安全的,因为恶意代理可以调用第 2 步所需的次数。我对此的问题是,恶意代理如何调用 misuse this 并多次调用该行代码。我显然在这里遗漏了一些东西。