DeFiFoundry
50,000 USDC
View results
Submission Details
Severity: low
Invalid

Potential use of tx.origin for authentication.

Summary

The function in GmxProxy.sol uses tx.origin for authentication to verify that the sender of the transaction is the owner of the contract. However, using tx.origin can lead to security vulnerabilities when users interact with the contract via other smart contracts. It is recommended to use msg.sender for authentication instead, as it more accurately reflects the immediate sender of the transaction.

Vulnerability Details

Using tx.origin for authentication checks is problematic because tx.origin returns the original sender of the transaction, which can be a contract address, rather than the immediate sender. This can create a security risk when users interact with the contract indirectly through other smart contracts. An attacker can exploit this by using another contract to initiate a transaction on behalf of the user, bypassing the intended authentication check.

Found Instance:

  1. GmxProxy.sol - Line 352:

    solidity

    CopyEdit

    require(tx.origin == owner(), "not owner");

    • This line checks that the original sender of the transaction is the contract owner. If this function is called via another contract, tx.origin will be the address of the user who initiated the transaction, allowing unintended interactions.

Impact

  • Security Bypass: If users interact with the contract through a third-party contract, they may bypass the ownership check, leading to unauthorized access or actions.

  • Vulnerability to Attacks: Malicious contracts can exploit this vulnerability by tricking the contract into thinking the transaction originator is the owner, allowing them to perform privileged actions.

  • Loss of Control: This practice weakens the control over sensitive operations like ownership transfer or fund withdrawals, as attackers can use intermediary contracts to impersonate the owner.

Tools Used

  • Static Analysis: The issue was detected using static code analysis tools (e.g., Slither, MythX, or CodeQL) to identify insecure practices like using tx.origin for authentication.

Recommendations

  1. Switch to msg.sender for Authentication:

    • Instead of using tx.origin, use msg.sender for authentication, as msg.sender always refers to the immediate sender of the transaction. This ensures that only the expected address (e.g., the contract owner) can execute certain actions.

    Example:

    solidity

    CopyEdit

    require(msg.sender == owner(), "not owner");

  2. Reevaluate Contract Logic:

    • Review the contract to ensure that there are no other places where tx.origin is used inappropriately for authentication, and replace it with msg.sender.

  3. Test Thoroughly:

    • Test the contract under various scenarios, especially where interactions with other contracts are involved, to ensure that msg.sender provides the intended security guarantees.

  4. Consider Additional Security Measures:

    • Implement other access control measures, such as multi-signature wallets or role-based access control (RBAC), to further secure sensitive actions in the contract.

Updates

Lead Judging Commences

n0kto Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

invalid_tx-origin

Lightchaser: Medium-5

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.