From 3d6cfbd8958aee52d0df998598fcf47ff5365806 Mon Sep 17 00:00:00 2001 From: defistar Date: Thu, 11 Jul 2024 00:51:28 +0530 Subject: [PATCH] feat: CCIP-2612 update revert behavior of _trialExecute to return error response on failures --- .../v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol | 16 ++-------------- .../ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol | 11 +++++++---- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol b/contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol index 9d1664cd66a..efd02072c3b 100644 --- a/contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol +++ b/contracts/src/v0.8/ccip/offRamp/EVM2EVMMultiOffRamp.sol @@ -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); @@ -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, ""); diff --git a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol index 4ab5acf3748..498b77b4fbf 100644 --- a/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol +++ b/contracts/src/v0.8/ccip/test/offRamp/EVM2EVMMultiOffRamp.t.sol @@ -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));