From 5bce10bdeb63fdf98125bb5eceb12cd8774012db Mon Sep 17 00:00:00 2001 From: ChiTimesChi <88190723+ChiTimesChi@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:35:32 +0100 Subject: [PATCH] fix: change V2 fields encoding order --- .../contracts-rfq/contracts/FastBridgeV2.sol | 2 +- .../contracts/libs/BridgeTransactionV2.sol | 41 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/contracts-rfq/contracts/FastBridgeV2.sol b/packages/contracts-rfq/contracts/FastBridgeV2.sol index 6692e4fe5e..65bccc5872 100644 --- a/packages/contracts-rfq/contracts/FastBridgeV2.sol +++ b/packages/contracts-rfq/contracts/FastBridgeV2.sol @@ -195,12 +195,12 @@ contract FastBridgeV2 is Admin, IFastBridgeV2, IFastBridgeV2Errors { originAmount: originAmount, destAmount: params.destAmount, originFeeAmount: originFeeAmount, - callValue: paramsV2.callValue, deadline: params.deadline, nonce: senderNonces[params.sender]++, // increment nonce on every bridge exclusivityRelayer: paramsV2.quoteRelayer, // We checked exclusivityEndTime to be in range (0 .. params.deadline] above, so can safely cast exclusivityEndTime: uint256(exclusivityEndTime), + callValue: paramsV2.callValue, callParams: paramsV2.callParams }) ); diff --git a/packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol b/packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol index 5445d4da9f..ccdecf58c6 100644 --- a/packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol +++ b/packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol @@ -18,11 +18,11 @@ library BridgeTransactionV2Lib { // uint256 originAmount [090 .. 122) // uint256 destAmount [122 .. 154) // uint256 originFeeAmount [154 .. 186) - // uint256 callValue [186 .. 218) - // uint256 deadline [218 .. 250) - // uint256 nonce [250 .. 282) - // address exclusivityRelayer [282 .. 302) - // uint256 exclusivityEndTime [302 .. 334) + // uint256 deadline [186 .. 218) + // uint256 nonce [218 .. 250) + // address exclusivityRelayer [250 .. 270) + // uint256 exclusivityEndTime [270 .. 302) + // uint256 callValue [302 .. 334) // bytes callParams [334 .. ***) // forgefmt: disable-start @@ -35,11 +35,11 @@ library BridgeTransactionV2Lib { uint256 private constant OFFSET_ORIGIN_AMOUNT = 90; uint256 private constant OFFSET_DEST_AMOUNT = 122; uint256 private constant OFFSET_ORIGIN_FEE_AMOUNT = 154; - uint256 private constant OFFSET_CALL_VALUE = 186; - uint256 private constant OFFSET_DEADLINE = 218; - uint256 private constant OFFSET_NONCE = 250; - uint256 private constant OFFSET_EXCLUSIVITY_RELAYER = 282; - uint256 private constant OFFSET_EXCLUSIVITY_END_TIME = 302; + uint256 private constant OFFSET_DEADLINE = 186; + uint256 private constant OFFSET_NONCE = 218; + uint256 private constant OFFSET_EXCLUSIVITY_RELAYER = 250; + uint256 private constant OFFSET_EXCLUSIVITY_END_TIME = 270; + uint256 private constant OFFSET_CALL_VALUE = 302; uint256 private constant OFFSET_CALL_PARAMS = 334; // forgefmt: disable-end @@ -74,11 +74,14 @@ library BridgeTransactionV2Lib { firstPart, bridgeTx.destAmount, bridgeTx.originFeeAmount, - bridgeTx.callValue, + // Note: we skip the deprecated `sendChainGas` flag, which was present in BridgeTransaction V1 bridgeTx.deadline, bridgeTx.nonce, + // New V2 fields: exclusivity bridgeTx.exclusivityRelayer, bridgeTx.exclusivityEndTime, + // New V2 fields: arbitrary call + bridgeTx.callValue, bridgeTx.callParams ); } @@ -188,14 +191,6 @@ library BridgeTransactionV2Lib { } } - /// @notice Extracts the call value from the encoded transaction. - function callValue(bytes calldata encodedTx) internal pure returns (uint256 callValue_) { - // Load 32 bytes from the offset. No shift is applied, as we need the full 256 bits. - assembly { - callValue_ := calldataload(add(encodedTx.offset, OFFSET_CALL_VALUE)) - } - } - /// @notice Extracts the deadline from the encoded transaction. function deadline(bytes calldata encodedTx) internal pure returns (uint256 deadline_) { // Load 32 bytes from the offset. No shift is applied, as we need the full 256 bits. @@ -228,6 +223,14 @@ library BridgeTransactionV2Lib { } } + /// @notice Extracts the call value from the encoded transaction. + function callValue(bytes calldata encodedTx) internal pure returns (uint256 callValue_) { + // Load 32 bytes from the offset. No shift is applied, as we need the full 256 bits. + assembly { + callValue_ := calldataload(add(encodedTx.offset, OFFSET_CALL_VALUE)) + } + } + /// @notice Extracts the call params from the encoded transaction. function callParams(bytes calldata encodedTx) internal pure returns (bytes calldata callParams_) { callParams_ = encodedTx[OFFSET_CALL_PARAMS:];