tx.origin authorization
tx.origin is the transaction's EOA, not the immediate caller, so any contract the user is tricked into calling inherits their authority — auth must compare msg.sender.
Procedure
- Find every use:
grep -nE 'tx\.origin' -r src/. - For each, check whether it gates a value-moving or privileged action. If it gates nothing, it is informational; if it gates a transfer, it is critical.
- Confirm the phishing path: victim EOA → attacker contract → victim contract;
msg.senderis the attacker buttx.originis the victim. - Write the PoC:
contract Phisher {
function attack(address wallet, bytes calldata data) external {
(bool ok,) = wallet.call(data); // tx.origin == victim, msg.sender == this
require(ok);
}
}
// test: vm.prank(victim); phisher.attack(address(bank), abi.encodeCall(bank.withdrawAll, ()));
- The fix is
require(msg.sender == owner). Verify the fixed build reverts from the Phisher withvm.expectRevert. - Also flag
tx.originused for replay protection or as a nonce source — it is not unique per call. - Check forwarded calls: a contract that does
target.call{value:...}with a user-supplied target lets the user'stx.originleak intotarget. - Scan dependencies:
grep -rn 'tx.origin' lib/ node_modules/for a transitive use behind your call. - Check
extcodesize"is-a-EOA" tricks: a contract in its constructor has no code, soextcodesize(msg.sender) == 0passes — do not use it for auth either. - Run the suite and confirm no legitimate path relies on the victim's EOA authority directly.
Pitfalls
tx.originin anonlyOwner-style modifier on a wallet that also accepts arbitrary calls — a single legitimate call drains it.require(tx.origin == msg.sender)as an anti-contract guard: it blocks legitimate multisig/AA wallets and is bypassable by a constructor call.- Test harnesses using
vm.pranksetmsg.senderbut nottx.origin, hiding the bug; usevm.prank(victim, victim)to set both. - Treating it as low severity because "it needs user interaction" — a malicious dapp front-end is exactly that interaction.
- Confusing
tx.originwithmsg.senderinside adelegatecall:msg.senderis preserved,tx.originis not.
Verification
forge test --match-test "testTxOrigin" -vvvv
Pass: the PoC drains the wallet in the vulnerable build and reverts with vm.expectRevert() after the msg.sender fix; grep -c 'tx\.origin' src/*.sol returns 0.
Report each tx.origin site, whether it gates value, and the PoC outcome.