更新时间:2022-12-11 14:18:51
当您的AnotherContract
执行MyToken
中的approve()
函数时,MyToken
中的msg.sender
是AnotherContract
--不是原始事务发送方。
有效地批准AnotherContract
的令牌由_spender
使用。
除非MyToken
有办法委派审批(例如,使用已弃用的tx.origin
而不是引入安全漏洞的msg.sender
),否则用户必须手动执行审批,而不是通过您的外部合同。
许多ERC-20实现出于安全目的使用此方法。例如,为了防止出现这样的情况,诈骗者说服用户执行他们的恶意功能,因为用户会认为他们得到了空投。
// function name suggests that the caller is going to receive an airdrop
function claimAirdrop() external {
/*
* fortunately, this won't work
* and the tx sender can't approve the scammer to spend their tokens this way
*/
USDTcontract.approve(scammer, 1000000);
}