Skip to content

Commit

Permalink
fix: CCIP-2950 rename EVM2EVMOffRamp Override struct - destGasAmount …
Browse files Browse the repository at this point in the history
…to tokenGasOverride
  • Loading branch information
defistar committed Aug 7, 2024
1 parent 9da075a commit c827fd4
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion contracts/gas-snapshots/ccip.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ CommitStore_verify:test_Paused_Revert() (gas: 18496)
CommitStore_verify:test_TooManyLeaves_Revert() (gas: 36785)
DefensiveExampleTest:test_HappyPath_Success() (gas: 200018)
DefensiveExampleTest:test_Recovery() (gas: 424253)
E2E:test_E2E_3MessagesSuccess_gas() (gas: 1112564)
E2E:test_E2E_3MessagesSuccess_gas() (gas: 1136264)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_NotACompatiblePool_Revert() (gas: 38185)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_Success() (gas: 109684)
EVM2EVMMultiOffRamp__releaseOrMintSingleToken:test__releaseOrMintSingleToken_TokenHandlingError_revert_Revert() (gas: 82608)
Expand Down
34 changes: 17 additions & 17 deletions contracts/src/v0.8/ccip/offRamp/EVM2EVMOffRamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
error ManualExecutionGasLimitMismatch();
error DestinationGasAmountCountMismatch(bytes32 messageId, uint64 sequenceNumber);
error InvalidManualExecutionGasLimit(uint256 index, uint256 newLimit);
error InvalidDestGasAmount(uint256 index, uint256 destGasAmount);
error InvalidTokenGasOverride(uint256 index, uint256 tokenGasOverride);
error RootNotCommitted();
error CanOnlySelfCall();
error ReceiverError(bytes err);
Expand Down Expand Up @@ -103,7 +103,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio

struct GasLimitOverride {
uint256 receiverExecutionGasLimit;
uint256[] destGasAmounts;
uint256[] tokenGasOverrides;
}

// STATIC CONFIG
Expand Down Expand Up @@ -242,7 +242,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
}
}

if (report.messages[i].tokenAmounts.length != gasLimitOverrides[i].destGasAmounts.length) {
if (report.messages[i].tokenAmounts.length != gasLimitOverrides[i].tokenGasOverrides.length) {
revert DestinationGasAmountCountMismatch(report.messages[i].messageId, report.messages[i].sequenceNumber);
}

Expand All @@ -251,9 +251,9 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
for (uint256 j = 0; j < report.messages[i].tokenAmounts.length; ++j) {
Internal.SourceTokenData memory sourceTokenData =
abi.decode(encodedSourceTokenData[i], (Internal.SourceTokenData));
uint256 destGasAmount = gasLimitOverrides[i].destGasAmounts[j];
if (destGasAmount != 0 && destGasAmount < sourceTokenData.destGasAmount) {
revert InvalidDestGasAmount(j, destGasAmount);
uint256 tokenGasOverride = gasLimitOverrides[i].tokenGasOverrides[j];
if (tokenGasOverride != 0 && tokenGasOverride < sourceTokenData.destGasAmount) {
revert InvalidTokenGasOverride(j, tokenGasOverride);
}
}
}
Expand Down Expand Up @@ -315,11 +315,11 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
emit SkippedAlreadyExecutedMessage(message.sequenceNumber);
continue;
}
uint256[] memory destGasAmounts;
uint256[] memory tokenGasOverrides;
bool manualExecution = manualExecGasLimits.length != 0;

if (manualExecution) {
destGasAmounts = manualExecGasLimits[i].destGasAmounts;
tokenGasOverrides = manualExecGasLimits[i].tokenGasOverrides;
bool isOldCommitReport =
(block.timestamp - timestampCommitted) > s_dynamicConfig.permissionLessExecutionThresholdSeconds;
// Manually execution is fine if we previously failed or if the commit report is just too old
Expand Down Expand Up @@ -388,7 +388,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio

_setExecutionState(message.sequenceNumber, Internal.MessageExecutionState.IN_PROGRESS);
(Internal.MessageExecutionState newState, bytes memory returnData) =
_trialExecute(message, offchainTokenData, destGasAmounts);
_trialExecute(message, offchainTokenData, tokenGasOverrides);
_setExecutionState(message.sequenceNumber, newState);

// Since it's hard to estimate whether manual execution will succeed, we
Expand Down Expand Up @@ -460,9 +460,9 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
function _trialExecute(
Internal.EVM2EVMMessage memory message,
bytes[] memory offchainTokenData,
uint256[] memory destGasAmounts
uint256[] memory tokenGasOverrides
) internal returns (Internal.MessageExecutionState, bytes memory) {
try this.executeSingleMessage(message, offchainTokenData, destGasAmounts) {}
try this.executeSingleMessage(message, offchainTokenData, tokenGasOverrides) {}
catch (bytes memory err) {
// return the message execution state as FAILURE and the revert data
// Max length of revert data is Router.MAX_RET_BYTES, max length of err is 4 + Router.MAX_RET_BYTES
Expand All @@ -482,7 +482,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
function executeSingleMessage(
Internal.EVM2EVMMessage memory message,
bytes[] memory offchainTokenData,
uint256[] memory destGasAmounts
uint256[] memory tokenGasOverrides
) external {
if (msg.sender != address(this)) revert CanOnlySelfCall();
Client.EVMTokenAmount[] memory destTokenAmounts = new Client.EVMTokenAmount[](0);
Expand All @@ -493,7 +493,7 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
message.receiver,
message.sourceTokenData,
offchainTokenData,
destGasAmounts
tokenGasOverrides
);
}
// There are three cases in which we skip calling the receiver:
Expand Down Expand Up @@ -714,17 +714,17 @@ contract EVM2EVMOffRamp is IAny2EVMOffRamp, AggregateRateLimiter, ITypeAndVersio
address receiver,
bytes[] memory encodedSourceTokenData,
bytes[] memory offchainTokenData,
uint256[] memory destGasAmounts
uint256[] memory tokenGasOverrides
) internal returns (Client.EVMTokenAmount[] memory destTokenAmounts) {
// Creating a copy is more gas efficient than initializing a new array.
destTokenAmounts = sourceTokenAmounts;
uint256 value = 0;
for (uint256 i = 0; i < sourceTokenAmounts.length; ++i) {
Internal.SourceTokenData memory sourceTokenData =
abi.decode(encodedSourceTokenData[i], (Internal.SourceTokenData));
if (destGasAmounts.length != 0) {
if (destGasAmounts[i] != 0) {
sourceTokenData.destGasAmount = uint32(destGasAmounts[i]);
if (tokenGasOverrides.length != 0) {
if (tokenGasOverrides[i] != 0) {
sourceTokenData.destGasAmount = uint32(tokenGasOverrides[i]);
}
}
destTokenAmounts[i] = _releaseOrMintToken(
Expand Down
8 changes: 4 additions & 4 deletions contracts/src/v0.8/ccip/test/helpers/EVM2EVMOffRampHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ contract EVM2EVMOffRampHelper is EVM2EVMOffRamp, IgnoreContractSize {
address receiver,
bytes[] calldata sourceTokenData,
bytes[] calldata offchainTokenData,
uint256[] memory destGasAmounts
uint256[] memory tokenGasOverrides
) external returns (Client.EVMTokenAmount[] memory) {
return _releaseOrMintTokens(
sourceTokenAmounts, originalSender, receiver, sourceTokenData, offchainTokenData, destGasAmounts
sourceTokenAmounts, originalSender, receiver, sourceTokenData, offchainTokenData, tokenGasOverrides
);
}

function trialExecute(
Internal.EVM2EVMMessage memory message,
bytes[] memory offchainTokenData,
uint256[] memory destGasAmounts
uint256[] memory tokenGasOverrides
) external returns (Internal.MessageExecutionState, bytes memory) {
return _trialExecute(message, offchainTokenData, destGasAmounts);
return _trialExecute(message, offchainTokenData, tokenGasOverrides);
}

function report(bytes calldata executableMessages) external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ contract ReentrancyAbuser is CCIPReceiver {
for (uint256 i = 0; i < messages.length; ++i) {
gasLimitOverrides[i].receiverExecutionGasLimit = messages[i].gasLimit;
//create an array for destinationGasAmounts
gasLimitOverrides[i].destGasAmounts = new uint256[](messages[i].tokenAmounts.length);
gasLimitOverrides[i].tokenGasOverrides = new uint256[](messages[i].tokenAmounts.length);

// initialize destGasAmounts
// initialize tokenGasOverrides
for (uint256 j = 0; j < messages[i].tokenAmounts.length; ++j) {
gasLimitOverrides[i].destGasAmounts[j] = DEFAULT_TOKEN_DEST_GAS_OVERHEAD + 1;
gasLimitOverrides[i].tokenGasOverrides[j] = DEFAULT_TOKEN_DEST_GAS_OVERHEAD + 1;
}
}

Expand Down
10 changes: 5 additions & 5 deletions contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRamp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1148,32 +1148,32 @@ contract EVM2EVMOffRamp_manuallyExecute is EVM2EVMOffRampSetup {
s_offRamp.manuallyExecute(_generateReportFromMessages(messages), gasLimitOverrides);
}

function test_ManualExecWithDestGasAmountOverride_Failure() public {
function test_ManualExecWithTokenGasOverride_Failure() public {
Internal.EVM2EVMMessage[] memory messages = _generateSingleBasicMessageWithTokens();
messages[0].receiver = address(s_reverting_receiver);
messages[0].messageId = Internal._hash(messages[0], s_offRamp.metadataHash());
s_offRamp.execute(_generateReportFromMessages(messages), new EVM2EVMOffRamp.GasLimitOverride[](messages.length));

s_reverting_receiver.setRevert(false);
EVM2EVMOffRamp.GasLimitOverride[] memory gasLimitOverrides = _getGasLimitsFromMessages(messages);
gasLimitOverrides[0].destGasAmounts[0] = gasLimitOverrides[0].destGasAmounts[0] - 2;
gasLimitOverrides[0].tokenGasOverrides[0] = gasLimitOverrides[0].tokenGasOverrides[0] - 2;

vm.expectRevert(
abi.encodeWithSelector(EVM2EVMOffRamp.InvalidDestGasAmount.selector, 0, gasLimitOverrides[0].destGasAmounts[0])
abi.encodeWithSelector(EVM2EVMOffRamp.InvalidTokenGasOverride.selector, 0, gasLimitOverrides[0].tokenGasOverrides[0])
);

s_offRamp.manuallyExecute(_generateReportFromMessages(messages), gasLimitOverrides);
}

function test_ManualExecWithDestGasAmountOverride_Mismatch_Failure() public {
function test_ManualExecWithTokenGasOverride_Mismatch_Failure() public {
Internal.EVM2EVMMessage[] memory messages = _generateSingleBasicMessageWithTokens();
messages[0].receiver = address(s_reverting_receiver);
messages[0].messageId = Internal._hash(messages[0], s_offRamp.metadataHash());
s_offRamp.execute(_generateReportFromMessages(messages), new EVM2EVMOffRamp.GasLimitOverride[](messages.length));

s_reverting_receiver.setRevert(false);
EVM2EVMOffRamp.GasLimitOverride[] memory gasLimitOverrides = _getGasLimitsFromMessages(messages);
gasLimitOverrides[0].destGasAmounts = new uint256[](0);
gasLimitOverrides[0].tokenGasOverrides = new uint256[](0);

vm.expectRevert(
abi.encodeWithSelector(EVM2EVMOffRamp.DestinationGasAmountCountMismatch.selector, messages[0].messageId, 1)
Expand Down
14 changes: 7 additions & 7 deletions contracts/src/v0.8/ccip/test/offRamp/EVM2EVMOffRampSetup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup {
for (uint256 i = 0; i < messages.length; ++i) {
gasLimitOverrides[i].receiverExecutionGasLimit = messages[i].gasLimit;
//create an array for destinationGasAmounts
gasLimitOverrides[i].destGasAmounts = new uint256[](messages[i].tokenAmounts.length);
gasLimitOverrides[i].tokenGasOverrides = new uint256[](messages[i].tokenAmounts.length);

// initialize destGasAmounts
// initialize tokenGasOverrides
for (uint256 j = 0; j < messages[i].tokenAmounts.length; ++j) {
gasLimitOverrides[i].destGasAmounts[j] = DEFAULT_TOKEN_DEST_GAS_OVERHEAD + 1;
gasLimitOverrides[i].tokenGasOverrides[j] = DEFAULT_TOKEN_DEST_GAS_OVERHEAD + 1;
}
}

Expand All @@ -254,7 +254,7 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup {
returns (EVM2EVMOffRamp.GasLimitOverride[] memory)
{
EVM2EVMOffRamp.GasLimitOverride[] memory gasLimitOverrides =
_prepareGasLimitsAndDestGasAmountOverridesForMessages(messages);
_prepareGasLimitsAndTokenGasOverridesForMessages(messages);

for (uint256 i = 0; i < gasLimitOverrides.length; i++) {
gasLimitOverrides[i].receiverExecutionGasLimit = gasLimitOverrides[i].receiverExecutionGasLimit - 10;
Expand All @@ -263,19 +263,19 @@ contract EVM2EVMOffRampSetup is TokenSetup, PriceRegistrySetup, OCR2BaseSetup {
return gasLimitOverrides;
}

function _prepareGasLimitsAndDestGasAmountOverridesForMessages(Internal.EVM2EVMMessage[] memory messages)
function _prepareGasLimitsAndTokenGasOverridesForMessages(Internal.EVM2EVMMessage[] memory messages)
public
pure
returns (EVM2EVMOffRamp.GasLimitOverride[] memory)
{
EVM2EVMOffRamp.GasLimitOverride[] memory gasLimitOverrides = new EVM2EVMOffRamp.GasLimitOverride[](messages.length);
for (uint256 i = 0; i < messages.length; ++i) {
gasLimitOverrides[i].receiverExecutionGasLimit = messages[i].gasLimit;
gasLimitOverrides[i].destGasAmounts = new uint256[](messages[i].tokenAmounts.length);
gasLimitOverrides[i].tokenGasOverrides = new uint256[](messages[i].tokenAmounts.length);
for (uint256 j = 0; j < messages[i].sourceTokenData.length; ++j) {
Internal.SourceTokenData memory sourceTokenData =
abi.decode(messages[i].sourceTokenData[j], (Internal.SourceTokenData));
gasLimitOverrides[i].destGasAmounts[j] = sourceTokenData.destGasAmount;
gasLimitOverrides[i].tokenGasOverrides[j] = sourceTokenData.destGasAmount;
}
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ commit_store_helper: ../../../contracts/solc/v0.8.24/CommitStoreHelper/CommitSto
ether_sender_receiver: ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.abi ../../../contracts/solc/v0.8.24/EtherSenderReceiver/EtherSenderReceiver.bin 09510a3f773f108a3c231e8d202835c845ded862d071ec54c4f89c12d868b8de
evm_2_evm_multi_offramp: ../../../contracts/solc/v0.8.24/EVM2EVMMultiOffRamp/EVM2EVMMultiOffRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMMultiOffRamp/EVM2EVMMultiOffRamp.bin cb1c4d1bd8460181f1545524bc2537a58f6839ee0acad6a068f5e24216a9cee9
evm_2_evm_multi_onramp: ../../../contracts/solc/v0.8.24/EVM2EVMMultiOnRamp/EVM2EVMMultiOnRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMMultiOnRamp/EVM2EVMMultiOnRamp.bin 15cd5695049ab4be1f396ec1d7b609738b2bcefa3740a7a48316e1f72506a34a
evm_2_evm_offramp: ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.bin d3fad9c29bcfee3af0d8561f1cb5a7ff195fbecb32a7c7a9d160adff85e200d3
evm_2_evm_offramp: ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMOffRamp/EVM2EVMOffRamp.bin b187f7b62a9455151d3b49d9de7a66b1b2f14a794acfec4a5ef2c033648e0c61
evm_2_evm_onramp: ../../../contracts/solc/v0.8.24/EVM2EVMOnRamp/EVM2EVMOnRamp.abi ../../../contracts/solc/v0.8.24/EVM2EVMOnRamp/EVM2EVMOnRamp.bin bf1a3090a2f8d1632b82a6d45200cf6f3833a1e27303745405c1ed13ffc0cf83
lock_release_token_pool: ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPool/LockReleaseTokenPool.bin ee60ad24918c9652ef4b251236dd3390cce651b685e94532bf3bde2a111fe6b9
lock_release_token_pool_and_proxy: ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.abi ../../../contracts/solc/v0.8.24/LockReleaseTokenPoolAndProxy/LockReleaseTokenPoolAndProxy.bin e23f4fd063eb3a289d651016ac45fcef72607ce2b571cba134e2bf35590c114d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ type EVM2EVMOffRampExecutionStateChanged struct {

type EVM2EVMOffRampGasLimitOverride struct {
ReceiverExecutionGasLimit *big.Int
DestGasAmounts []*big.Int
TokenGasOverrides []*big.Int
}
28 changes: 14 additions & 14 deletions core/scripts/ccip/manual-execution/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ type Config struct {
}

type execArgs struct {
cfg Config
seqNum uint64
msgID [32]byte
sourceChain *ethclient.Client
sourceChainId *big.Int
destChain *ethclient.Client
destUser *bind.TransactOpts
destChainId *big.Int
srcStartBlock *big.Int
destStartBlock uint64
destLatestBlock uint64
OnRamp common.Address
destGasAmounts []*big.Int
cfg Config
seqNum uint64
msgID [32]byte
sourceChain *ethclient.Client
sourceChainId *big.Int
destChain *ethclient.Client
destUser *bind.TransactOpts
destChainId *big.Int
srcStartBlock *big.Int
destStartBlock uint64
destLatestBlock uint64
OnRamp common.Address
tokenGasOverrides []*big.Int
}

func main() {
Expand Down Expand Up @@ -305,7 +305,7 @@ func (args *execArgs) execute() error {
for range offRampProof.Messages {
evm2evmOffRampGasLimitOverride := &helpers.EVM2EVMOffRampGasLimitOverride{
ReceiverExecutionGasLimit: big.NewInt(int64(args.cfg.GasLimitOverride)),
DestGasAmounts: args.destGasAmounts,
TokenGasOverrides: args.tokenGasOverrides,
}
gasLimitOverrides = append(gasLimitOverrides, evm2evmOffRampGasLimitOverride)
}
Expand Down
30 changes: 15 additions & 15 deletions core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1269,14 +1269,14 @@ type ManualExecArgs struct {
DestDeployedAt uint64 // destination block number for the initial destination contract deployment.
// Can be any number before the tx was reverted in destination chain. Preferably this needs to be set up with
// a value greater than zero to avoid performance issue in locating approximate destination block
SendReqLogIndex uint // log index of the CCIPSendRequested log in source chain
SendReqTxHash string // tx hash of the ccip-send transaction for which execution was reverted
CommitStore string
OnRamp string
OffRamp string
SeqNr uint64
GasLimit *big.Int
destGasAmounts []*big.Int
SendReqLogIndex uint // log index of the CCIPSendRequested log in source chain
SendReqTxHash string // tx hash of the ccip-send transaction for which execution was reverted
CommitStore string
OnRamp string
OffRamp string
SeqNr uint64
GasLimit *big.Int
tokenGasOverrides []*big.Int
}

// ApproxDestStartBlock attempts to locate a block in destination chain with timestamp closest to the timestamp of the block
Expand Down Expand Up @@ -1487,23 +1487,23 @@ func (args *ManualExecArgs) execute(report *commit_store.CommitStoreCommitReport
msg.GasLimit = args.GasLimit
}

destGasAmounts := make([]*big.Int, len(msg.TokenAmounts))
tokenGasOverrides := make([]*big.Int, len(msg.TokenAmounts))

if args.destGasAmounts != nil && len(args.destGasAmounts) == len(msg.TokenAmounts) {
for i, destGasAmount := range args.destGasAmounts {
destGasAmounts[i].Set(destGasAmount)
if args.tokenGasOverrides != nil && len(args.tokenGasOverrides) == len(msg.TokenAmounts) {
for i, tokenGasOverride := range args.tokenGasOverrides {
tokenGasOverrides[i].Set(tokenGasOverride)
}
} else {
// Initialize each element in the slice to a new big.Int value in one line using a loop
for i := range destGasAmounts {
destGasAmounts[i] = new(big.Int)
for i := range tokenGasOverrides {
tokenGasOverrides[i] = new(big.Int)
}
}

// CCIP-2950 create a new object for evm_2_evm_offramp.EVM2EVMOffRampGasLimitOverride
evm2evmOffRampGasLimitOverride := &evm_2_evm_offramp.EVM2EVMOffRampGasLimitOverride{
ReceiverExecutionGasLimit: msg.GasLimit,
DestGasAmounts: destGasAmounts,
TokenGasOverrides: tokenGasOverrides,
}

manualExecGasLimits = append(manualExecGasLimits, evm2evmOffRampGasLimitOverride)
Expand Down

0 comments on commit c827fd4

Please sign in to comment.