OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: high
Likelihood: low
Invalid

Admin Key Compromise

Description


The OrderBook contract utilizes the Ownable pattern, granting a single external address (owner) exclusive control over several critical functions. If this single owner's private key is compromised, an attacker would gain full administrative control over the protocol's configuration and treasury management functions, leading to severe consequences.


Risk


Root Cause: The Ownable pattern centralizes administrative control to a single address, creating a single point of failure.

Solidity

// Functions with onlyOwner modifier, directly controllable by a single compromised key:
function setAllowedSellToken(address _token, bool _isAllowed) external onlyOwner { ... }
function emergencyWithdrawERC20(address _tokenAddress, uint256 _amount, address _to) external onlyOwner { ... }
function withdrawFees(address _to) external onlyOwner { ... }

Likelihood: Medium. While direct smart contract vulnerabilities are not the cause, private key compromises (e.g., phishing, weak security practices, insider threat) are a common attack vector in the blockchain space. The likelihood increases with the value controlled by the key.

Impact: High.

  • Loss of Protocol Fees: A compromised owner can call withdrawFees to drain all accumulated protocol fees.

  • Arbitrary Token Withdrawal (Rug Pull Vector): The emergencyWithdrawERC20 function (as previously discussed in a dedicated finding) allows the owner to withdraw any non-core ERC20 tokens accidentally or intentionally sent to the contract. A compromised owner could use this to drain such funds.

  • Market Manipulation/Disruption: The owner can call setAllowedSellToken to disable legitimate trading tokens or enable malicious ones, disrupting the order book's intended functionality.

  • Reputational Damage: A successful attack due to a compromised admin key severely damages user trust and the protocol's reputation.


Proof of Concept


This is a direct consequence of a compromised private key; no complex exploit code is needed within the smart contract itself.

Scenario:

  1. The private key associated with the OrderBook contract's owner address is compromised (e.g., via a phishing attack, malware, or insider collusion).

  2. The attacker gains control of the owner address.

  3. The attacker then calls withdrawFees(attacker_address) to steal all accumulated protocol fees.

  4. The attacker could also monitor for any accidental ERC20 deposits (non-core tokens) and use emergencyWithdrawERC20(accidental_token_address, amount, attacker_address) to drain those funds.

  5. The attacker could call setAllowedSellToken(iWETH, false) to disable trading of WETH, severely impacting the protocol's functionality and user experience.


Recommended Mitigation


To significantly reduce the risk associated with a single point of failure, implement operational security best practices for the owner's address.

  1. Multi-Signature Wallet:

    • Transfer ownership of the OrderBook contract to a multi-signature wallet (e.g., Gnosis Safe, Safe). This requires a predefined number of trusted signers (e.g., 3 out of 5) to approve any administrative action, making it much harder for a single compromised key to cause damage.

    • Pro: Greatly enhances security and decentralizes control.

    • Con: Adds overhead to administrative operations.

  2. Time-Locked Admin Actions:

    • Implement a time-lock mechanism for critical owner-only functions. This means that after an owner initiates a sensitive action (e.g., withdrawing fees, changing allowed tokens), there's a mandatory delay (e.g., 24-72 hours) before the action can be executed.

    • Pro: Provides a window for the community or other guardians to detect and react to malicious or unauthorized actions.

    • Con: Delays legitimate administrative actions.

Proposed Change (Conceptual - requires external setup or a dedicated Timelock contract): The contract code itself would ideally remain onlyOwner, but the owner address would point to a multi-sig wallet or a Timelock contract. No direct Solidity code change is presented here, as this is an architectural/operational change.


Reference Files:

  • src/OrderBook.sol

Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

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