Skip to content

Commit

Permalink
feat: CCIP-2612 update revert behavior of _trialExecute to return err…
Browse files Browse the repository at this point in the history
…or response on failures
  • Loading branch information
defistar committed Jul 10, 2024
1 parent c10a0f0 commit 3d6cfbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
16 changes: 2 additions & 14 deletions contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ contract EVM2EVMMultiOffRamp is ITypeAndVersion, MultiOCR3Base {
}

_setExecutionState(sourceChainSelector, message.header.sequenceNumber, Internal.MessageExecutionState.IN_PROGRESS);

(Internal.MessageExecutionState newState, bytes memory returnData) = _trialExecute(message, offchainTokenData);
_setExecutionState(sourceChainSelector, message.header.sequenceNumber, newState);

Expand Down Expand Up @@ -465,21 +466,8 @@ contract EVM2EVMMultiOffRamp is ITypeAndVersion, MultiOCR3Base {
) internal returns (Internal.MessageExecutionState, bytes memory) {
try this.executeSingleMessage(message, offchainTokenData) {}
catch (bytes memory err) {
bytes4 errorSelector = bytes4(err);
if (
ReceiverError.selector == errorSelector || TokenHandlingError.selector == errorSelector
|| Internal.InvalidEVMAddress.selector == errorSelector || InvalidDataLength.selector == errorSelector
|| CallWithExactGas.NoContract.selector == errorSelector || NotACompatiblePool.selector == errorSelector
|| IMessageInterceptor.MessageValidationError.selector == errorSelector
) {
// If CCIP receiver execution is not successful, bubble up receiver revert data,
// prepended by the 4 bytes of ReceiverError.selector, TokenHandlingError.selector or InvalidPoolAddress.selector.
// Max length of revert data is Router.MAX_RET_BYTES, max length of err is 4 + Router.MAX_RET_BYTES
// return the message execution state as FAILURE and the revert data
return (Internal.MessageExecutionState.FAILURE, err);
} else {
// If revert is not caused by CCIP receiver, it is unexpected, bubble up the revert.
revert ExecutionError(message.header.messageId, err);
}
}
// If message execution succeeded, no CCIP receiver return data is expected, return with empty bytes.
return (Internal.MessageExecutionState.SUCCESS, "");
Expand Down
11 changes: 7 additions & 4 deletions contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,14 @@ contract EVM2EVMMultiOffRamp_executeSingleReport is EVM2EVMMultiOffRampSetup {
Internal.ExecutionReportSingleChain memory executionReport =
_generateReportFromMessages(SOURCE_CHAIN_SELECTOR_1, messages);

vm.expectRevert(
vm.expectEmit();
emit EVM2EVMMultiOffRamp.ExecutionStateChanged(
messages[0].header.sourceChainSelector,
messages[0].header.sequenceNumber,
messages[0].header.messageId,
Internal.MessageExecutionState.FAILURE,
abi.encodeWithSelector(
EVM2EVMMultiOffRamp.ExecutionError.selector,
messages[0].header.messageId,
abi.encodeWithSelector(CallWithExactGas.NotEnoughGasForCall.selector)
CallWithExactGas.NotEnoughGasForCall.selector
)
);
s_offRamp.executeSingleReport(executionReport, new uint256[](0));
Expand Down

0 comments on commit 3d6cfbd

Please sign in to comment.