Skip to content

Commit

Permalink
fix: change V2 fields encoding order
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Oct 16, 2024
1 parent 3555d77 commit 5bce10b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);
Expand Down
41 changes: 22 additions & 19 deletions packages/contracts-rfq/contracts/libs/BridgeTransactionV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
);
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:];
Expand Down

0 comments on commit 5bce10b

Please sign in to comment.