Skip to content
Access control Audit finding Intermediate

VaultProxy implementation can be initialized by anyone and self-destructed

The VaultProxy implementation contract's initialise function was left unprotected, allowing anyone to set its staderConfig address to a malicious contract. An attacker could then trigger a delegatecall that self-destructs the implementation, causing all vault clones to forward calls to an address with no code and return success without executing logic.

broccolirob Follow with dwward3n, hals and 2 others

Originally disclosed on Code4rena

Submitted by broccolirob, also found by dwward3n, hals, bin2chen, and 0x70C9

https://github.com/code-423n4/2023-06-stader/blob/7566b5a35f32ebd55d3578b8bd05c038feb7d9cc/contracts/VaultProxy.sol#L20-L36 https://github.com/code-423n4/2023-06-stader/blob/7566b5a35f32ebd55d3578b8bd05c038feb7d9cc/contracts/VaultProxy.sol#L41-L50

When the VaultFactory contract is deployed and initialized, the initialise method on the newly created VaultProxy implementation contract is never called. As such, anyone can call that method and pass in whatever values they want as arguments. One important argument is the _staderConfig address, which controls where the fallback function will direct delegatecall operations. If an attacker passes in a contract that calls selfdestruct, it will be run in the context of the VaultProxy implementation contract and will erase all code from that address. Since the clones from the VaultProxy contract merely delegate calls to the implementation address, all subsequent calls for all created vaults from that implementation will be treated like an EOA and return true, even though calls to functions on that proxy were never executed.

Proof of Concept

  • First, an attacker deploys a contract called AttackContract that calls selfdestruct in its fallback function.
contract AttackContract {
    function getValidatorWithdrawalVaultImplementation() public view returns(address) {
        return address(this);
    }
    function getNodeELRewardVaultImplementation() public view returns(address) {
	return address(this);
    }
    fallback(bytes calldata _input) external payable returns(bytes memory _output) {
	selfdestruct(address(0));
    }
}
  • The attacker calls the initialise method on the VaultProxy implementation contract. That address is stored in the vaultProxyImplementation variable on the VaultFactory contract. The attacker passes in the address of AttackContract as the _staderConfig argument for the initialise function.
  • The attacker then calls a non-existent function on the VaultProxy implementation contract, which triggers it’s fallback function. The fallback function calls staderConfig.getNodeELRewardVaultImplementation(), and since staderConfig is set the AttackContract address, it returns the address of the AttackContract. delegatecall runs the fallback function of AttackContract in its own execution environment. selfdestruct is called in the execution environment of the VaultProxy implementation, which erases the code at that address.
  • All cloned copies of the VaultProxy implementation contract are now forwarding calls to an implementation address that has no code stored at it. These calls will be treated like calls to an EOA and return true for success.

Recommended Mitigation Steps

Prevent the initialise function from being called on the VaultProxy implementation contract by inheriting from OpenZeppelin’s Initializable contract, like the system is doing in other contracts. Call the _disableInitializers function in the constructor and protect initialise with the initializer modifier. Alternatively, the initialise function can be called from the initialize function of the VaultFactory contract when the VaultProxy contract is instantiated.

Assessed type

Access Control

Picodes (judge) commented:

Keeping High severity. This seems exploitable to lock funds with no cost, as the fallback function is payable.

sanjay-staderlabs (Stader) confirmed

sanjay-staderlabs (Stader) commented:

This is fixed in the code.


The original report as published on Code4rena, by broccolirob. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The initialise function on the VaultProxy implementation contract was not restricted, so anyone could set the staderConfig address to a malicious contract that self-destructs during a delegatecall.

Impact

All vaults created from the affected implementation would stop executing logic while still returning success, which could lock funds.

What the attacker needed

None

The fix

The issue was fixed by preventing initialise from being called on the implementation, for example by using OpenZeppelin's Initializable with _disableInitializers in the constructor.

How it was found

  1. Deploy an attack contract whose fallback function calls selfdestruct.
  2. Call initialise on the VaultProxy implementation, passing the attack contract as the staderConfig address.
  3. Call a non-existent function on the implementation to trigger its fallback, which delegatecalls the attack contract and self-destructs the implementation.
  4. All cloned vaults now forward calls to an address with no code and return true for success.

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 contract forwards calls to a separate implementation contract that holds the actual code. If an attacker can make the proxy run a self-destruct command, the implementation's code is erased, so every proxy using it silently fails while still reporting success.

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.

More by broccolirob

View all

2 more disclosed reports, best first.

More from Stader Labs

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.