skka3134

skka3134

email
telegram

Smart Contract Security: 2. Bypassing EOA Check

What is bypassing EOA check?

Many DeFi contracts only allow EOA to perform critical operations. Contract addresses cannot be invoked. This is achieved by checking msg.sender. However, attackers can bypass this check by forging msg.sender as an EOA address in their malicious contracts using EOS or delegatecall.

Methods to prevent bypassing EOA check:

Check not only msg.sender but also tx.origin to ensure that the caller is an EOA.
Use state variables to record EOA on the user's first call and enforce the use of recordedEOA for subsequent calls.
Perform EOA check in secure interface contracts, allowing users to only call through these interface contracts.
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.