it’s possible to initialize contract BkdLocker for multiple times by sending startBoost=0 and each time different values for other parameters
The initialisation guard in the BkdLocker contract checked a configuration value that the caller could set to zero, so the contract could be initialised more than once. A malicious governance caller could change boost and withdraw-delay settings, leading to unfair reward distribution and loss of yield.
Originally disclosed on Code4rena
Submitted by unforgiven, also found by 0x1f8b and scaraven
function initialize() of BkdLocker suppose to be called one time and contract initialize one time. but if it’s called by startBoost=0 then it’s possible to call it again with different values for other parameters. there are some logics based on the values function initilize() sets which is in calculating boost and withdraw delay. by initializing multiple times different users get different values for those logics and because rewards are distributed based on boosts so those logics will be wrong too.
Proof of Concept
This is initiliaze() code in BkdLocker:
function initialize(
uint256 startBoost,
uint256 maxBoost,
uint256 increasePeriod,
uint256 withdrawDelay
) external override onlyGovernance {
require(currentUInts256[_START_BOOST] == 0, Error.CONTRACT_INITIALIZED);
_setConfig(_START_BOOST, startBoost);
_setConfig(_MAX_BOOST, maxBoost);
_setConfig(_INCREASE_PERIOD, increasePeriod);
_setConfig(_WITHDRAW_DELAY, withdrawDelay);
}
As you can see it checks the initialization statue by currentUInts256[_START_BOOST]’s value but it’s not correct way to do and initializer can set currentUInts256[_START_BOOST] value as 0 and set other parameters values and call this function multiple times with different values for _MAX_BOOST and _INCREASE_PERIOD and _WITHDRAW_DELAY. setting different values for those parameters can cause different calculation in computeNewBoost() and prepareUnlock(). function computeNewBoost() is used to calculate users boost parameters which is used on reward distribution. so by changing _MAX_BOOST the rewards will be distributed wrongly between old users and new users.
Tools Used
VIM
Recommended Mitigation Steps
Add some other variable to check the status of initialization of contract.
danhper (Backd) confirmed, but disagreed with severity
Alex the Entreprenerd (judge) commented:
The warden has shown how, under specific circumstances, the
BkdLockercontact can be initialized multiple times, with the specific goal of changing configuration parameters.From my understanding these configs are meant to be set only once (there are no available external setters that governance can call), effectively sidestepping the “perceived immutability” that the locker seems to be offering.
The attack is contingent on malicious Governance, for that reason I believe Medium Severity to be appropriate.
The impact of the attack can cause:
- Loss of Yield
- Unfair distribution of rewards
- Abuse of rewards math for governance advantage
End users can verify that the exploit is not applicable by ensuring that
startBoostis greater than 0.
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 initialisation guard used a configurable parameter (startBoost) as its sentinel instead of a dedicated boolean flag, so passing zero left the contract looking uninitialised.
Impact
Rewards could be distributed unfairly between old and new users and yield could be lost, but only a malicious governance caller could carry out the attack.
What the attacker needed
Governance privileges on the contract; startBoost set to zero
The fix
The contract should track initialisation with a separate dedicated variable rather than relying on a configurable parameter.
How it was found
- Call the initialize function with startBoost set to zero and chosen values for the other parameters.
- Call initialize again with startBoost still zero but different values for maxBoost, increasePeriod and withdrawDelay.
- Observe that the configuration values are overwritten and boost and unlock calculations change.
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 is a program on a blockchain that runs automatically. This one had a one-time setup function meant to run only once, but its 'already set up?' check relied on a value the caller could leave at zero, so setup could be repeated. Repeating setup let the caller change reward rules after people had already joined.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.