5.1.6 tx.origin

Never use tx.origin for authorization. Let’s say you have a wallet contract like this:

pragma solidity ^0.4.0;

// THIS CONTRACT CONTAINS A BUG - DO NOT USE
contract TxUserWallet {

    address owner;

    function TxUserWallet() {
        owner = msg.sender;
    }

    function transfer(address dest, uint amount) {
        if (tx.origin != owner) { throw; }
        if (!dest.call.value(amount)()) throw;
    }
}

Now someone tricks you into sending ether to the address of this attack wallet:

pragma solidity ^0.4.0;

contract TxAttackWallet {

    address owner;

    function TxAttackWallet() {
        owner = msg.sender;
    }

    function() {
        TxUserWallet(msg.sender).transfer(owner, msg.sender.balance);
    }
}

If your wallet had checked msg.sender for authorization, it would get the address of the attack wallet, instead of the owner address. But by checking tx.origin, it gets the original address that kicked off the transaction, which is still the owner address. The attack wallet instantly drains all your funds.

results matching ""

    No results matching ""