Lack of check on mustStartAtOrAfter
The contract lacked a check on the `mustStartAtOrAfter` parameter, allowing a project owner to set a huge value that overflows when packed, potentially setting the funding cycle start time to any value including the past. This could bypass the ballot waiting time depending on the ballot's implementation.
Submitted by zzzitron, also found by IllIllI
Impact
By setting huge mustStartAtOrAfter, the owner can set start time in the past. It might open up possibility to bypass the ballot waiting time depending on the ballot’s implementation.
Proof of Concept
The proof of concept is almost the same as TestReconfigure::testReconfigureProject. In the original test, the owner of the project is reconfiguring funding cycle, but it is not in effect immediately because ballot is set. Only after 3 days the newly set funding cycle will be the current one.
In the above proof of concept, only one parameter of the funding cycle is modified: mustStartAtOrAfter is set to type(uint56).max. As the result, the newly set funding cycle is considered as the current one without waiting for the ballot.
The cause of this is missing check on mustStartAtOrAfter upon setting here. If the given _mustStartAtOrAfter is huge, it will be passed eventually to the _initFor, _packAndStoreIntrinsicPropertiesOf. Then it will ‘overflow’ by shifting and set to the funding cycle, which essentially can be set to any value including the past. Also, it seems like the number will be also effected because the bigger digit will carry over.
// in JBFundingCycleStore::_packAndStoreIntrinsicPropertiesOf
// where the `_start` is derived from `_mustStartAtOrAfter`
./JBFundingCycleStore.sol-518- // start in bits 144-199.
./JBFundingCycleStore.sol:519: packed |= _start << 144;
./JBFundingCycleStore.sol-520-
./JBFundingCycleStore.sol-521- // number in bits 200-255.
./JBFundingCycleStore.sol-522- packed |= _number << 200;
Tools Used
Foundry
Recommended Mitigation Steps
Add a check for the _mustStartAtOrAfter:
// example check for _mustSTartAtOrAfter
// in JBFundingCycleStore::configureFor
if (_mustStartAtOrAfter > type(uint56).max) revert INVALID_START();
drgorillamd (Juicebox) confirmed and commented:
We’ve seen the POC, now assessing how to best mitigate (at what level).
jack-the-pug (judge) commented:
Good catch!
drgorillamd (Juicebox) resolved:
PR with fix: PR #1
berndartmueller (warden) reviewed mitigation:
mustStartAtOrAfterand the start date of an upcoming funding cycle are now validated to fit inuint56.
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 missing validation on the `_mustStartAtOrAfter` parameter before packing it into a limited bit field, causing an overflow that can set the start time to an arbitrary value.
Impact
The owner could set the start time in the past, potentially bypassing the ballot waiting time depending on the ballot's implementation.
What the attacker needed
Owner of a project; ballot with waiting time
The fix
The fix adds a check that `_mustStartAtOrAfter` fits within `uint56`, and the start date of an upcoming funding cycle is now validated.
How it was found
- The project owner reconfigures the funding cycle, setting `mustStartAtOrAfter` to a very large value.
- The huge value is passed to `_initFor` and then to `_packAndStoreIntrinsicPropertiesOf`.
- When packing, the value overflows and the start time is set to an arbitrary value, including the past.
- The newly set funding cycle becomes current immediately, without waiting for the ballot delay.
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 stores a start time for funding cycles. The code didn't check that the requested start time was within a valid range, so a very large number could wrap around and become a past date. This might let the owner skip a waiting period.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.