Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCIP-4919 fix missing case in gas estimation logic #15984

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/.changeset/soft-glasses-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@chainlink/contracts': patch
---

#internal fix missing case in gas estimation logic


PR issue: CCIP-4919

Solidity Review issue: CCIP-3966
13 changes: 6 additions & 7 deletions contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ OffRamp_commit:test_ReportOnlyRootSuccess_gas() (gas: 141051)
OffRamp_commit:test_RootWithRMNDisabled() (gas: 153873)
OffRamp_commit:test_StaleReportWithRoot() (gas: 232057)
OffRamp_commit:test_ValidPriceUpdateThenStaleReportWithRoot() (gas: 206700)
OffRamp_constructor:test_Constructor() (gas: 6311247)
OffRamp_constructor:test_Constructor() (gas: 6322677)
OffRamp_execute:test_LargeBatch() (gas: 3373860)
OffRamp_execute:test_MultipleReports() (gas: 291458)
OffRamp_execute:test_MultipleReportsWithPartialValidationFailures() (gas: 364826)
Expand Down Expand Up @@ -278,13 +278,12 @@ OffRamp_releaseOrMintTokens:test_releaseOrMintTokens_WithGasOverride() (gas: 163
OffRamp_releaseOrMintTokens:test_releaseOrMintTokens_destDenominatedDecimals() (gas: 174276)
OffRamp_setDynamicConfig:test_SetDynamicConfig() (gas: 25442)
OffRamp_setDynamicConfig:test_SetDynamicConfigWithInterceptor() (gas: 47493)
OffRamp_trialExecute:test_trialExecute() (gas: 263614)
OffRamp_trialExecute:test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() (gas: 24490)
OffRamp_trialExecute:test_trialExecute() (gas: 263680)
OffRamp_trialExecute:test_trialExecute_RateLimitError() (gas: 120710)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() (gas: 29391)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() (gas: 29539)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 131932)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 281327)
OffRamp_trialExecute:test_trialExecute_RevertsWhen_SenderIsGasEstimator_InsufficientGasForToCompleteTx() (gas: 67132)
OffRamp_trialExecute:test_trialExecute_SenderIsNotGasEstimator_CallWithExactGasReverts() (gas: 24573)
OffRamp_trialExecute:test_trialExecute_TokenHandlingErrorIsCaught() (gas: 131998)
OffRamp_trialExecute:test_trialExecute_TokenPoolIsNotAContract() (gas: 281305)
OnRampTokenPoolReentrancy:test_OnRampTokenPoolReentrancy() (gas: 245406)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates() (gas: 325996)
OnRamp_applyAllowlistUpdates:test_applyAllowlistUpdates_InvalidAllowListRequestDisabledAllowListWithAdds() (gas: 17190)
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/v0.8/ccip/ocr/MultiOCR3Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract contract MultiOCR3Base is ITypeAndVersion, Ownable2StepMsgSender {
error NonUniqueSignatures();
error OracleCannotBeZeroAddress();
error StaticConfigCannotBeChanged(uint8 ocrPluginType);
error InsufficientGasForCallWithExact();
error InsufficientGasToCompleteTx(bytes4 err);

/// @dev Packing these fields used on the hot path in a ConfigInfo variable reduces the retrieval of all
/// of them to a minimum number of SLOADs.
Expand Down
3 changes: 2 additions & 1 deletion contracts/src/v0.8/ccip/offRamp/OffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,9 @@ contract OffRamp is ITypeAndVersion, MultiOCR3Base {
if (
CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG == bytes4(err)
|| CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG == bytes4(err)
|| ERC165CheckerReverting.InsufficientGasForStaticCall.selector == bytes4(err)
) {
revert InsufficientGasForCallWithExact();
revert InsufficientGasToCompleteTx(bytes4(err));
}
}
// return the message execution state as FAILURE and the revert data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.24;

import {CallWithExactGas} from "../../../../shared/call/CallWithExactGas.sol";
import {ERC165CheckerReverting} from "../../../libraries/ERC165CheckerReverting.sol";
import {Internal} from "../../../libraries/Internal.sol";
import {RateLimiter} from "../../../libraries/RateLimiter.sol";
import {MultiOCR3Base} from "../../../ocr/MultiOCR3Base.sol";
Expand Down Expand Up @@ -120,58 +121,46 @@ contract OffRamp_trialExecute is OffRampSetup {
assertEq(abi.encodeWithSelector(OffRamp.NotACompatiblePool.selector, address(0)), err);
}

function test_trialExecute_CallWithExactGasRevertsAndSenderIsNotGasEstimator() public {
function test_trialExecute_SenderIsNotGasEstimator_CallWithExactGasReverts() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, new uint32[](0))),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);

(Internal.MessageExecutionState newState, bytes memory err) =
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
s_offRamp.trialExecute(message, offchainTokenData, new uint32[](0));
assertEq(uint256(Internal.MessageExecutionState.FAILURE), uint256(newState));
assertEq(CallWithExactGas.NotEnoughGasForCall.selector, bytes4(err));
}

function test_trialExecute_RevertsWhen_NoGasForCallExactCheckAndSenderIsGasEstimator() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeWithSelector(CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG, "")
);
function test_trialExecute_RevertsWhen_SenderIsGasEstimator_InsufficientGasForToCompleteTx() public {
bytes4[3] memory sigs = [
CallWithExactGas.NO_GAS_FOR_CALL_EXACT_CHECK_SIG,
CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG,
ERC165CheckerReverting.InsufficientGasForStaticCall.selector
];

changePrank(Internal.GAS_ESTIMATION_SENDER);
vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
}

function test_trialExecute_RevertsWhen_NoEnoughGasForCallSigAndSenderIsGasEstimator() public {
Internal.Any2EVMRampMessage memory message =
_generateAny2EVMMessageNoTokens(SOURCE_CHAIN_SELECTOR_1, ON_RAMP_ADDRESS_1, 1);

bytes[] memory offchainTokenData = new bytes[](message.tokenAmounts.length);
uint32[] memory tokenGasOverrides = new uint32[](0);

vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, tokenGasOverrides)),
abi.encodeWithSelector(CallWithExactGas.NOT_ENOUGH_GAS_FOR_CALL_SIG, "")
);
for (uint256 i = 0; i < sigs.length; ++i) {
vm.mockCallRevert(
address(s_offRamp),
abi.encodeCall(s_offRamp.executeSingleMessage, (message, offchainTokenData, new uint32[](0))),
abi.encodeWithSelector(sigs[i])
);

changePrank(Internal.GAS_ESTIMATION_SENDER);

changePrank(Internal.GAS_ESTIMATION_SENDER);
vm.expectRevert(MultiOCR3Base.InsufficientGasForCallWithExact.selector);
s_offRamp.trialExecute(message, offchainTokenData, tokenGasOverrides);
vm.expectRevert(abi.encodeWithSelector(MultiOCR3Base.InsufficientGasToCompleteTx.selector, sigs[i]));
s_offRamp.trialExecute(message, offchainTokenData, new uint32[](0));
}
}
}
Loading
Loading