Staking graph argument bounds are incorrectly defined
The StakingGraph library defines its DELTA and PRODUCT bounds with a misplaced parenthesis, so the constants are far larger than intended. An attacker could pass an amount that passes the library's own bounds check but then reverts inside the update logic, and in a theoretical worst case corrupt the internal data structure.
- Disclosed after under an hour
57806 sc low staking graph argument bounds are incorrectly defined
Submitted on Oct 29th 2025 at 00:42:27 UTC by @a16 for Audit Comp | Alchemix V3
- Report ID: #57806
- Report Type: Smart Contract
- Report severity: Low
- Target: https://github.com/alchemix-finance/v3-poc/blob/immunefi\\_audit/src/libraries/StakingGraph.sol
- Impacts:
Description
Brief/Intro
The DELTA_MAX, DELTA_MIN, PRODUCT_MAX and PRODUCT_MIN constants are incorrectly defined.
Vulnerability Details
The following constants are incorrectly defined:
int256 private constant DELTA_MAX = int256(2**DELTA_BITS - 1)-1;
int256 private constant DELTA_MIN = -int256(2**DELTA_BITS - 1);
int256 private constant PRODUCT_MAX = int256(2**PRODUCT_BITS - 1)-1;
int256 private constant PRODUCT_MIN = -int256(2**PRODUCT_BITS - 1);
This is likely a typing error, as there should have been parenthesis in the power argument like so:
int256 private constant DELTA_MAX = int256(2**(DELTA_BITS - 1))-1;
int256 private constant DELTA_MIN = -int256(2**(DELTA_BITS - 1));
int256 private constant PRODUCT_MAX = int256(2**(PRODUCT_BITS - 1))-1;
int256 private constant PRODUCT_MIN = -int256(2**(PRODUCT_BITS - 1));
Impact Details
Library function accepts values that would likely cause an unexpected revert, and perhaps also data corruption in the theoretical worse case (sign bits in the internal data structure could potentially flip, causing the library to return incorrect results). There's likely no real impact on the Alchemist protocol itself, since the values required to trigger this incorrect behavior are unrealistically large.
Proof of Concept
PoC demonstrating that values that are supposed to be accepted according to the constants defined in the library actually revert:
/// Externalized helper so Foundry can catch the internal revert on update(...) function _addStakeExternal(int256 amount, uint256 start, uint256 duration) external { graph.addStake(amount, start, duration); }
function test_BoundsBug_ParamAccepted_ButRevertsInsideUpdate() public { // Pick a value that passes the library’s CURRENT (wrong) DELTA bounds (sign bit set), // but triggers a revert during Fenwick accumulation. int256 amount = (int256(1) << 111); // Reverts for values >= 2^111 uint256 start = 1234; uint256 duration = 1;
console.log("start"); console.log(start);
console.log("duration"); console.log(duration);
console.log("amount"); console.logInt(amount);
vm.expectRevert();
this._addStakeExternal(amount, start, duration);
}
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 a misplaced parenthesis in the exponent expression, so the constants are computed as 2 to the power of the bit count rather than 2 to the power of the bit count minus one.
Impact
Values that the library's own constants say are acceptable can cause an unexpected revert, and in a theoretical worst case could flip sign bits and corrupt the internal data structure; the report says there is likely no real impact on the Alchemist protocol because the required values are unrealistically large.
What the attacker needed
Ability to call addStake with a very large amount
The fix
The constants should be redefined with the parenthesis around the subtraction so the bounds match the intended bit width.
How it was found
- Call the external helper that forwards to the library's addStake function.
- Pass an amount that passes the current wrong DELTA bounds but is at least 2^111.
- Observe that the call reverts inside the update logic instead of being rejected by the bounds check.
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 library stores numbers in a packed data structure and uses constants to decide the largest value it can safely hold. A typo in how those constants are calculated made the limits much bigger than the storage can handle. A caller can therefore pass a value the library says is allowed, but the library then fails or misbehaves while processing it.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.