skka3134

skka3134

email
telegram

Smart Contract Security: 2. Bypassing EOA Check

What is bypassing EOA check?

Many DeFi contracts only allow Externally Owned Accounts (EOA) to perform critical operations. Contract addresses cannot be called. This is achieved by checking msg.sender. However, attackers can bypass this check by spoofing msg.sender as an EOA address in their malicious contract using EOS or delegatecall.

Methods to prevent bypassing EOA check:

Check not only msg.sender but also tx.origin to ensure the caller is an EOA.
Use a state variable to record the EOA on the user's first call and enforce the use of recordedEOA for subsequent calls.
Perform EOA checks in secure interface contracts, where users can only call through this interface contract.
Use audited security libraries like OpenZeppelin's EOAChecker.

Code example:

// Also check tx.origin
require(msg.sender == tx.origin, "Not EOA");

// Record EOA on first call
address public userEOA; 

function initEOA() external {
  require(userEOA == address(0), "Already initialized");
  userEOA = msg.sender;
}

function criticalFunc() external {
  require(msg.sender == userEOA, "Only EOA can call");
  
  // Function logic
}
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.