Non-normalized amounts sent via Wormhole lead to failure to redeem incentives
Withheld amounts synced from L2 via Wormhole were not normalised to 8 decimals before being subtracted from transfer amounts on L1, causing dust accumulation and preventing some users from redeeming incentives on L2.
Wormhole only supports sending tokens in 8 decimal precision. This is addressed in the code via the getBridgingDecimals() method, which is overridden in WormholeDepositProcessorL1 to return 8. This is then passed as parameter to calculateStakingIncentives() in the Dispenser contract to normalize the transferAmount sent via the bridge to the smaller precision and return the remaining amount to the Tokenomics contract.
However, the withheld amount from the target chain is then subtracted from the transferAmount, so it’s important that this amount is also normalized in order to avoid precision loss if the resulting amount after subtracting became unnormalized. This is highlighted in the code in the following comment:
File: Dispenser.sol
1010: // Note: in case of normalized staking incentives with bridging decimals, this is correctly managed
1011: // as normalized amounts are returned from another side
1012: uint256 withheldAmount = mapChainIdWithheldAmounts[chainId];
1013: if (withheldAmount > 0) {
1014: // If withheld amount is enough to cover all the staking incentives, the transfer of OLAS is not needed
1015: if (withheldAmount >= transferAmount) {
1016: withheldAmount -= transferAmount;
1017: transferAmount = 0;
1018: } else {
1019: // Otherwise, reduce the transfer of tokens for the OLAS withheld amount
1020: transferAmount -= withheldAmount;
1021: withheldAmount = 0;
1022: }
1023: mapChainIdWithheldAmounts[chainId] = withheldAmount;
1024: }
However, this is not actually the case and withheld amounts returned via Wormhole are in fact unnormalized. While the amounts are normalized if synced via the fallback privileged syncWithheldAmountMaintenance() function, this logic isn’t implemented in the syncWithheldAmount() function, which will be called in the normal flow of operations as follows:
receiveWormholeMessages() will then pass the same unnormalized amount to Tokenomics.syncWithheldAmount().
Impact
Unnormalized amount will be sent via Wormhole any time a withheld amount is synced from L2. This has several consequences:
Dust amounts will be accumulated in the WormholeDepositProcessorL1 contract.
More severely, some users will be unable to redeem their incentives on L2 due to the difference between the total OLAS balance of the WormholeTargetDispenserL2 (withheld amount + normalized transferAmount after bridging) contract and the total incentives calculated in the L1 dispenser (withheld amount + unnormalized transferAmount after subtracting withheld amount).
Proof of Concept
WormholeTargetDispenserL2 withholds 0.123456789 OLAS (unnormalized).
Anyone calls syncWithheldTokens() to send the unnormalized amount to L1.
WormholeDepositProcessorL1 receives the unnormalized amount and calls syncWithheldAmount() on the Dispenser contract.
Dispenser updates its records with the unnormalized amount of 0.123456789 OLAS.
A user claims incentives on L1.
Dispenser calculates the transferAmount as 0.2 OLAS.
Dispenser subtracts the unnormalized withheld amount, resulting in a transferAmount of 0.076543211 OLAS.
WormholeDepositProcessorL1 sends 0.07654321 OLAS to L2 via Wormhole and keeps 0.000000001 OLAS (Wormhole only transfers the normalized amount from the caller)
The user tries to redeem incentives on L2.
WormholeTargetDispenserL2 has 0.199999999 OLAS (withheld amount + 0 OLAS from L1).
The user cannot redeem due to the discrepancy.
Recommended Mitigation Steps
Implement the normalizing logic in syncWithheldAmount() as well.
All the staking amounts are normalized before being sent to L2. Thus, the sum of normalized amounts on L2 is normalized, and the only withheldAmount sent back to L1 is normalized by default. This is why that check on L1 is not needed.
@0xA5DF and @kupermind, you are right that the staking amounts are normalized before being sent to L2, which helps ensure consistency in many cases. However, the emissions limiting mechanism can play a key role in this context affecting the withheld amount.
Specifically, when the verifyInstanceAndGetEmissionsAmount() function is called, it returns the lower of:
The emissionsAmount() returned by the staking contract instance, which is calculated on initialization based on the _stakingParams
The amount returned by StakingVerifier.getEmissionsAmountLimit (instance), which returns a fixed limit defined when the staking limits are changed
These emission amounts are calculated based on parameters with second-level granularity, making it very unlikely that normalized values for these amounts were intended, or could be achieved in the first place. As a result, the withheld amount derived from this process would also be unnormalized.
Ok, this seems correct. We need to normalize the withheld amount on the L2 side before sending, such that all the unnormalized amount is left on L2.
This amount limiting part of code was literally added in a rush during the last day before the audit, that’s why there was a firm feeling things are in order.
syncWithheldAmount function is modified correctly which passes normalized amount to dispensor. One additional modification made in syncWithheldAmountMaintenance in dispensor (i.e., amount is not normalized).
As it mentions, that exact data which failed to get delivered will be passed and as admin calls this function, we expect the normalized amount will be passed.
/// @dev Syncs the withheld amount manually by the DAO in order to restore the data that was not delivered from L2.
/// @notice The parameters here must correspond to the exact data failed to be delivered (amount, batch).
/// The possible bridge failure scenario that requires to act via the DAO vote includes:
/// - Message from L2 to L1 fails: need to call this function.
/// @param chainId L2 chain Id.
/// @param amount Withheld amount that was not delivered from L2.
/// @param batchHash Unique batch hash for each message transfer.
function syncWithheldAmountMaintenance(uint256 chainId, uint256 amount, bytes32 batchHash) external {
// Check the contract ownership
if (msg.sender != owner) {
revert OwnerOnly(msg.sender, owner);
}
// Check zero value chain Id and amount
if (chainId == 0 || amount == 0 || batchHash == 0) {
revert ZeroValue();
}
// The sync must never happen for the L1 chain Id itself, as dispenser exists strictly on L1-s
if (chainId == block.chainid) {
revert WrongChainId(chainId);
}
// Note: all the amounts coming from events of undelivered messages are already normalized
uint256 withheldAmount = mapChainIdWithheldAmounts[chainId] + amount;
// The overall amount is bound by the OLAS projected maximum amount for years to come
if (withheldAmount > type(uint96).max) {
revert Overflow(withheldAmount, type(uint96).max);
}
// Add to the withheld amount
mapChainIdWithheldAmounts[chainId] = withheldAmount;
// Get deposit processor address corresponding to the specified chain Id
address depositProcessor = mapChainIdDepositProcessors[chainId];
// Update the batch hash on deposit processor side
IDepositProcessor(depositProcessor).updateHashMaintenance(batchHash);
emit WithheldAmountSynced(chainId, amount, withheldAmount, batchHash);
}
The original report as published on Code4rena, by EV_om. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
Dust amounts could accumulate in the WormholeDepositProcessorL1 contract and some users could be unable to redeem their incentives on L2 due to the balance discrepancy.
What the attacker needed
Withheld amount synced from L2; Wormhole bridge used
The fix
The normalising logic was added to syncWithheldAmount() so that the withheld amount is normalised on the L2 side before being sent.
How it was found
A WormholeTargetDispenserL2 contract withholds an unnormalised amount.
Anyone calls syncWithheldTokens() to send the unnormalised amount to L1.
WormholeDepositProcessorL1 receives the amount and calls syncWithheldAmount() on the Dispenser.
The Dispenser records the unnormalised withheld amount.
A user claims incentives on L1 and the Dispenser subtracts the unnormalised withheld amount from the transfer amount.
WormholeDepositProcessorL1 sends only the normalised amount to L2, leaving a discrepancy that prevents the user from redeeming incentives on L2.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When tokens are sent between blockchains, some bridges only accept amounts with a fixed number of decimal places. This report found that a withheld amount was sent back without being rounded to that precision, so the numbers on the two chains did not match and some users could not claim their rewards.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.