Flaw in upgradeToAndCall leads to the proxy cal
The proxy's upgradeToAndCall function calls itself via address(this).call, so the implementation receives the proxy's own address as the caller instead of the Timelock owner. As a result, any initialisation call that checks the owner will revert, preventing the upgrade from completing.
- Disclosed after under an hour
25921 - [SC - Insight] Flaw in upgradeToAndCall leads to the proxy cal...
Submitted on Nov 21st 2023 at 03:11:43 UTC by @neth for Boost | DeGate
Report ID: #25921
Report type: Smart Contract
Report severity: Insight
Target: https://etherscan.io/address/0x54D7aE423Edb07282645e740C046B9373970a168#code
Impacts:
- Contract fails to deliver promised returns, but doesn't lose value
Description
Bug Description
In OwnedUpgradeabilityProxy, function upgradeToAndCall
function upgradeToAndCall(address implementation, bytes memory data) payable public onlyProxyOwner {
upgradeTo(implementation);
(bool success, ) = address(this).call{value: msg.value}(data);
require(success);
}
calls himself by doing address(this).call..., which redirects to the fallback function in Proxy with msg.sender == address(this), instead of directly delegatecalling to the implementation with the caller being Timelock, which is bad as proxies are not supposed to "initiate" transactions, but delegate them.
Impact
In the implementation, the owner is responsible for calling setCheckBalance, which is, at the moment, an EOA (see https://etherscan.io/address/0xacD3A62F3eED1BfE4fF0eC8240d645c1F5477F82) but it seems it will be Timelock in the future. That means it is NOT, by any means, the proxy, so trying to update the implementation via upgradeToAndCall will revert, as the modifier will check for msg.sender == owner with owner != address(proxy).
The same applies to ExchangeProxy
Recommendation
function upgradeToAndCall(address implementation, bytes memory data) payable public onlyProxyOwner {
upgradeTo(implementation);
- (bool success, ) = address(this).call{value: msg.value}(data);
+ _fallback();
require(success);
}
Proof of concept
(Simplified POC, if you need the mainnet fork I can give it to you but it was far more verbose)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console2} from "forge-std/Test.sol";
contract Proxy {
fallback() payable external {
console2.log("Caller in Proxy::fallback, which is gonna be passed to impl (shall be Timelock)");
console2.log(msg.sender);
console2.log("");
console2.log("It was the address of the Proxy, see the next log which outputs address(this)");
console2.log(address(this));
}
function updateToAndCall() external {
console2.log("Caller in Proxy::updateToAndCall, that is, Timelock");
console2.log(msg.sender);
console2.log("");
address(this).call("");
}
}
contract POC is Test {
Proxy internal proxy;
function setUp() external {
proxy = new Proxy();
}
function testPOC() external {
console2.log("Address of the initial caller, that is, Timelock");
console2.log(address(this));
console2.log("");
proxy.updateToAndCall();
}
}
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 upgradeToAndCall function uses address(this).call instead of delegatecalling the implementation, so msg.sender becomes the proxy rather than the original owner.
Impact
Upgrades that rely on upgradeToAndCall will revert when the implementation checks that the caller is the owner, so the contract fails to deliver the promised upgrade behaviour, though no funds are lost.
What the attacker needed
Proxy owner is a contract, not the proxy itself
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 proxy is a contract that forwards calls to another contract (the implementation) while keeping its own storage. The upgrade function is supposed to forward the setup call as if the owner (a Timelock contract) made it, but instead it makes the call from the proxy itself. Because the implementation checks that the caller is the owner, the setup call fails and the upgrade cannot be completed.
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.