I used this code in a smart contract method on Polygon blockchain:
function withdraw() public {
iERC20 tether = iERC20(0xc2132D05D31c914a87C6611C10748AEb04B58e8F);
tether.transfer(msg.sender, tether.balanceOf(address(this)));
}
Note: I forgot to make this function onlyOwner
.
At the beginning there was 50 Tethers in the smart contract. When I called this method, 0 tether transferred to my wallet and the smart contract became empty!
I traced the transaction and wondered to see this consecutive transactions in the smart contract at one block:
The last destination at the top is my wallet and both of the other destinations accounts are contracts:
0xa8f4098f0c9b5b3ab59844d0d5e070f8f7524ec9
0x4bfd2181be8fa2f6702dee41a46baabeb5d3dd3d
Note that the destination 0xa8f4... is marked as instant withdrawals and was instantly discharged.
How hackers can aware this vulnerability of a method and send their transactions instantly before my transaction? Are they in the Polygonscan organization that receive our sent transactions?
Note: I sent my transaction via Metamask wallet.