Governance mechanism could be exploited to free
The Timelock contract allows an admin to queue and execute arbitrary transactions, including sending funds to a contract that cannot return them. If the admin account is compromised, an attacker could permanently freeze funds by sending them to a contract with no withdrawal function.
- Disclosed after under an hour
26104 - [SC - Insight] Governance mechanism could be exploited to free...
Submitted on Nov 24th 2023 at 21:40:44 UTC by @cheatcode for Boost | DeGate
Report ID: #26104
Report type: Smart Contract
Report severity: Insight
Target: https://etherscan.io/address/0xf2991507952d9594e71a44a54fb19f3109d213a5#code
Impacts:
- Permanent freezing of funds from the Default Deposit Contract that requires malicious actions from the DeGate Operator.
Description
Governance mechanism could be exploited to freeze assets permanently in the case of a compromised admin.
Summary
The Timelock contract allows an admin to queue and later execute any transaction. This is a powerful feature intended for governance, giving the ability to perform various actions, including transferring funds. The executeTransaction function in the contract makes a generic call to any address with any provided data payload. This means it can call any function on any contract, including those that might lock funds. It should be noted that contract does not inherently distinguish between safe and unsafe transactions. If the admin queues a transaction that sends funds to a malicious contract designed to lock funds permanently, the Timelock contract has no built-in mechanism to prevent this.
For instance, a transaction could be queued to send Ether to a contract that has no function to withdraw funds, effectively locking them. The security of the Timelock contract heavily relies on the trustworthiness and security of the admin account. If this account is compromised, the attacker can queue malicious transactions. Also, if governance processes are not robust, a malicious or negligent admin could intentionally queue a harmful transaction.
The timelock mechanism delays the execution of transactions, which is a double-edged sword. While it provides time to review transactions, it also means once a malicious transaction is queued, and the delay period begins, there’s a window during which the funds are at risk if no one intervenes. There’s no built-in mechanism in the contract for stakeholders to intervene, cancel, or modify a transaction once it's queued (unless such actions are taken by the admin).
Example Scenario
Imagine the admin queues a transaction sending a large amount of Ether to a contract that functions as a "black hole" – it can receive Ether but has no functionality to transfer it out. Once the Timelock delay elapses and the transaction is executed, those funds become permanently locked in the black hole contract.
Mitigation Strategies
- Implementing a whitelist system, where only trusted contracts can be interacted with, could mitigate the risk.
- Requiring multiple signatures for queueing transactions can reduce the risk of a single compromised admin account.
- Establishing and following a strict governance process for reviewing and approving transactions before they are queued.
- Implementing a way for stakeholders to propose and vote on the cancellation of a queued transaction.
Impact
Permanent freezing of funds
Proof of Concept
The vulnerability arises from the potent combination of the Timelock contract's powerful capabilities and the reliance on the admin's role. Without additional safeguards, this setup can potentially be exploited to permanently freeze assets.
Objective
To show how a maliciously crafted transaction, once executed through the Timelock contract, can result in the permanent freezing of funds.
Setup
-
Deploy the Timelock Contract: Deploy your
Timelockcontract on a test network. -
Deploy a Malicious Contract: Create and deploy a contract designed to freeze funds. This could be a simple contract with a function that can receive and lock funds, without a way to withdraw them.
Solidity contract MaliciousContract { function lockFunds() external payable { // Funds are received but there are no methods to withdraw them } } -
Tools and Environment: Use a development environment like Remix, Truffle, or Hardhat for deploying and interacting with the contracts.
Execution Steps
-
As an attacker with control over the
adminaccount (or through a compromised admin account), queue a malicious transaction in theTimelockcontract targeting theMaliciousContractwith a significant amount of Ether.Solidity // Parameters for the malicious transaction address target = address(maliciousContract); uint value = largeEtherAmount; string memory signature = "lockFunds()"; bytes memory data = abi.encodeWithSignature(signature); // Queue the transaction in Timelock timelock.queueTransaction(target, value, signature, data, eta); -
Wait for the time lock period (
eta) to pass. -
Execute the queued transaction after the timelock period.
Solidity timelock.executeTransaction(target, value, signature, data, eta); -
Check the balance of the
MaliciousContractto confirm that the funds are locked and inaccessible.
Expected Results
- The
MaliciousContractreceives and locks the funds sent from theTimelockcontract. - There is no function in the
MaliciousContractto withdraw or release the funds, demonstrating a permanent freeze.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the Timelock contract executes arbitrary calls without any validation or safeguard, so a compromised admin can send funds to a contract that cannot return them.
Impact
Funds from the Default Deposit Contract could be permanently frozen if the admin account is compromised and a malicious transaction is queued and executed.
What the attacker needed
Compromised admin account; timelock delay period elapses
The fix
The report suggests implementing a whitelist of trusted contracts, requiring multiple signatures for queuing transactions, establishing a strict governance process, and allowing stakeholders to propose and vote on cancellation of queued transactions.
How it was found
- Deploy the Timelock contract on a test network.
- Deploy a contract that can receive funds but has no function to withdraw them.
- As the admin, queue a transaction in the Timelock contract that sends a large amount of Ether to that contract.
- Wait for the timelock delay period to pass.
- Execute the queued transaction.
- Check the balance of the malicious contract to confirm the funds are locked and cannot be retrieved.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A timelock contract lets an administrator schedule actions that run after a delay. This report says that if an attacker takes over the admin account, they can schedule a transfer of funds to a contract that can receive money but has no way to send it back, so the money is stuck forever. The contract itself does not check whether a scheduled action is safe.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.