Skip to content

Commit 6c6d9b9

Browse files
add missing feequoter math test (#322)
* wip: template * test: some overflow cases * ref: overwrites param * test: 0 token value * test: unreachable errors * fix: remove redundant test * fix: unreachable FeeCalculationOverflow * ref: max uint notation * fix: inconsistency in calculation
1 parent c2452b8 commit 6c6d9b9

File tree

4 files changed

+364
-52
lines changed

4 files changed

+364
-52
lines changed

contracts/contracts/ccip/fee_quoter/contract.tolk

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,17 @@ get fun validatedFee(msg: Router_CCIPSend): coins {
217217

218218
val it = (msg.data as SnakedCell<uint8>).iter();
219219
val (msgDataLen, errorCode) = it.countBytesSafe();
220-
if (errorCode == ERROR_INVALID_DATA) {
221-
throw FeeQuoter_Error.InvalidMsgData;
222-
} else if (errorCode == 8) {
223-
throw FeeQuoter_Error.MsgDataTooLarge;
220+
match (errorCode) {
221+
0 => { /* continue */ }
222+
8 => {
223+
throw FeeQuoter_Error.MsgDataTooLarge;
224+
}
225+
ERROR_INVALID_DATA => {
226+
throw FeeQuoter_Error.InvalidMsgData;
227+
}
228+
else => {
229+
throw errorCode;
230+
}
224231
}
225232

226233
var gasLimit = validateMessageAndResolveGasLimitForDestination(msg.extraArgs, destChainConfig.config, msg, msgDataLen);
@@ -283,13 +290,13 @@ fun _dataAvailabilityCost(
283290
// dest_data_availability_overhead_gas is a separate config value for flexibility to be updated
284291
// independently of message codestChainConfig. Its value is determined by CCIP lane implementation, e.g.
285292
// the overhead data posted for OCR.
286-
val daLengthCost = mustProd(dataAvailabilityLengthBytes, destChainConfig.config.destGasPerDataAvailabilityByte as uint256, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
287-
val dataAvailabilityGas = mustAdd(daLengthCost, destChainConfig.config.destDataAvailabilityOverheadGas as uint256, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
293+
val daLengthCost = mustProd(dataAvailabilityLengthBytes, destChainConfig.config.destGasPerDataAvailabilityByte, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
294+
val dataAvailabilityGas = mustAdd(daLengthCost, destChainConfig.config.destDataAvailabilityOverheadGas, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
288295

289296
// data_availability_gas_price is in 18 decimals, dest_data_availability_multiplier_bps is in 4 decimals
290297
// We pad 14 decimals to bring the result to 36 decimals, in line with token bps and execution fee.
291298
val daPrice = mustProd(dataAvailabilityGasPrice, dataAvailabilityGas, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
292-
val daWithMultiplier = mustProd(daPrice, destChainConfig.config.destDataAvailabilityMultiplierBps as uint256, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
299+
val daWithMultiplier = mustProd(daPrice, destChainConfig.config.destDataAvailabilityMultiplierBps, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
293300
return mustProd(daWithMultiplier, VAL_1E14, FeeQuoter_Error.DataAvailabilityCostOverflow as int);
294301
}
295302

contracts/contracts/ccip/fee_quoter/errors.tolk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ enum FeeQuoter_Error {
1717
InsufficientFee
1818
TokenTransfersNotSupported
1919
// Overflow protection errors
20-
ExecutionCostOverflow
21-
PremiumFeeOverflow
22-
DataAvailabilityCostOverflow
23-
FeeCalculationOverflow
20+
ExecutionCostOverflow // Unreachable
21+
PremiumFeeOverflow // Unreachable
22+
DataAvailabilityCostOverflow // Unreachable
23+
FeeCalculationOverflow // Unreachable
2424
TokenPriceTooLow
2525
FeeOverflow
2626
}

0 commit comments

Comments
 (0)