Owner in VaultProxy.sol is address(0)
The initialise function in StaderConfig grants the admin role but does not update the mapping that getAdmin reads from, so getAdmin returns address(0). As a result, VaultProxy.initialise sets its owner to address(0), making all owner-restricted functions inaccessible until updateAdmin is called.
josephdara Follow with ksk2345, Aymen0909 and 3 others
Originally disclosed on Code4rena
Submitted by josephdara, also found by ksk2345, Aymen0909, bin2chen, ChrisTina, and NoamYakov
The owner variable in the VaultProxy.sol is going to be zero because of a bug in staderConfig. The intialize function in staderConfig grants the admin role to an admin passed in the native _grantRole(), but does not update the mapping that getAdmin reads from.
function initialise(
bool _isValidatorWithdrawalVault,
uint8 _poolId,
uint256 _id,
address _staderConfig
) external {
if (isInitialized) {
revert AlreadyInitialized();
}
UtilLib.checkNonZeroAddress(_staderConfig);
isValidatorWithdrawalVault = _isValidatorWithdrawalVault;
isInitialized = true;
poolId = _poolId;
id = _id;
staderConfig = IStaderConfig(_staderConfig);
//@audit-issue Admin is zero on initialize
//address(0) is going to be returned, wrt stader.initialize
owner = staderConfig.getAdmin();
}
https://github.com/code-423n4/2023-06-stader/blob/7566b5a35f32ebd55d3578b8bd05c038feb7d9cc/contracts/StaderConfig.sol#L85-L103 https://github.com/code-423n4/2023-06-stader/blob/7566b5a35f32ebd55d3578b8bd05c038feb7d9cc/contracts/StaderConfig.sol#L361-L363
The intialization of the vaults would not revert and all functions restricted to the owner would be inaccessible, unless function updateAdmin is called.
The update admin does not revoke functions for the current admin in the AccessControl contract either, because the address returned is address zero.
Proof of Concept
pragma solidity 0.8.16;
import '../../contracts/library/UtilLib.sol';
import '../../contracts/StaderConfig.sol';
import '../../contracts/VaultProxy.sol';
import '../../contracts/ValidatorWithdrawalVault.sol';
import '../../contracts/OperatorRewardsCollector.sol';
import './mocks/PoolUtilsMock.sol';
import './mocks/PenaltyMockForVault.sol';
import './mocks/SDCollateralMock.sol';
import './mocks/StakePoolManagerMock.sol';
import 'forge-std/Test.sol';
import '@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol';
import '@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol';
contract ValidatorWithdrawalVaultTest is Test {
address staderAdmin;
address staderManager;
address staderTreasury;
PoolUtilsMock poolUtils;
uint8 poolId;
uint256 validatorId;
StaderConfig staderConfig;
VaultProxy withdrawVault;
OperatorRewardsCollector operatorRC;
function setUp() public {
poolId = 1;
validatorId = 1;
staderAdmin = vm.addr(100);
staderManager = vm.addr(101);
address ethDepositAddr = vm.addr(102);
ProxyAdmin proxyAdmin = new ProxyAdmin();
StaderConfig configImpl = new StaderConfig();
TransparentUpgradeableProxy configProxy = new TransparentUpgradeableProxy(
address(configImpl),
address(proxyAdmin),
''
);
staderConfig = StaderConfig(address(configProxy));
staderConfig.initialize(staderAdmin, ethDepositAddr);
OperatorRewardsCollector operatorRCImpl = new OperatorRewardsCollector();
TransparentUpgradeableProxy operatorRCProxy = new TransparentUpgradeableProxy(
address(operatorRCImpl),
address(proxyAdmin),
''
);
operatorRC = OperatorRewardsCollector(address(operatorRCProxy));
operatorRC.initialize(staderAdmin, address(staderConfig));
poolUtils = new PoolUtilsMock(address(staderConfig));
PenaltyMockForVault penaltyContract = new PenaltyMockForVault();
SDCollateralMock sdCollateral = new SDCollateralMock();
ValidatorWithdrawalVault withdrawVaultImpl = new ValidatorWithdrawalVault();
vm.startPrank(staderAdmin);
staderConfig.updatePoolUtils(address(poolUtils));
staderConfig.updatePenaltyContract(address(penaltyContract));
staderConfig.updateSDCollateral(address(sdCollateral));
staderConfig.updateOperatorRewardsCollector(address(operatorRC));
staderConfig.updateValidatorWithdrawalVaultImplementation(address(withdrawVaultImpl));
vm.stopPrank();
withdrawVault = new VaultProxy();
withdrawVault.initialise(true, poolId, validatorId, address(staderConfig));
}
function testAdminRights() public {
vm.startPrank(staderAdmin);
staderConfig.grantRole(staderConfig.MANAGER(), staderManager);
vm.stopPrank();
}
function testFetchAdminAndVaultOwner() public{
address _admin = staderConfig.getAdmin();
assertEq(_admin, address(0));
address _owner = withdrawVault.owner();
assertEq(_owner, address(0));
}
}
Tools Used
Foundry
Recommended Mitigation Steps
StaderConfig.initialize should add setAccount(ADMIN, _admin); at the last line.
Assessed type
Access Control
Picodes (judge) decreased severity to Medium
sanjay-staderlabs (Stader) disagreed with severity, acknowledged and commented:
We are handling it as a part of the deployment process;
updateAdmin(address _admin)is called during deployment process.
sanjay-staderlabs (Stader) commented:
@Picodes - can you please check this? It think it should be part for QA. Thanks
Considering the audited version of the code, especially in combination with issue 390, I still think this qualifies for Medium severity.
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 initialise function in StaderConfig grants the admin role via _grantRole but fails to update the mapping that getAdmin reads, so getAdmin returns address(0).
Impact
All functions restricted to the owner become inaccessible until updateAdmin is called, and updateAdmin does not revoke roles for the current admin because the returned address is zero.
What the attacker needed
Deployment of StaderConfig and VaultProxy
The fix
StaderConfig.initialize should also set the admin in the mapping that getAdmin reads, for example by calling setAccount(ADMIN, _admin).
How it was found
- Deploy StaderConfig and call initialize with an admin address.
- Deploy VaultProxy and call initialise, which sets owner = staderConfig.getAdmin().
- Observe that getAdmin returns address(0) and the vault owner is address(0).
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 smart contract has an owner who is allowed to do special actions. Here, a setup mistake meant the owner was set to the zero address, which is like setting it to nobody. That locked everyone out of owner-only functions until a separate fix was applied.
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.