Skip to content

Commit

Permalink
feat(contracts-rfq): save destination chain ID for requested bridges …
Browse files Browse the repository at this point in the history
…[SLT-423] (#3356)

* feat: don't save `proofBlockNumber`

* test: refactor status/proof checks

* feat: add `destChainId`, tests

* feat: make sure BridgeTxDetails is exactly 256 bits
  • Loading branch information
ChiTimesChi authored Nov 4, 2024
1 parent 1c3afa8 commit 5e11d4d
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 63 deletions.
20 changes: 10 additions & 10 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
// Aggregate the read operations from the same storage slot
address disputedRelayer = $.proofRelayer;
BridgeStatus status = $.status;
uint40 proofBlockTimestamp = $.proofBlockTimestamp;
uint56 proofBlockTimestamp = $.proofBlockTimestamp;
// Can only dispute a RELAYER_PROVED transaction within the dispute period
if (status != BridgeStatus.RELAYER_PROVED) revert StatusIncorrect();
if (_timeSince(proofBlockTimestamp) > DISPUTE_PERIOD) {
Expand All @@ -100,7 +100,6 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
$.status = BridgeStatus.REQUESTED;
$.proofRelayer = address(0);
$.proofBlockTimestamp = 0;
$.proofBlockNumber = 0;

emit BridgeProofDisputed(transactionId, disputedRelayer);
}
Expand Down Expand Up @@ -221,7 +220,9 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
})
);
bytes32 transactionId = keccak256(request);
// Note: the tx status will be updated throughout the tx lifecycle, while destChainId is set once here
bridgeTxDetails[transactionId].status = BridgeStatus.REQUESTED;
bridgeTxDetails[transactionId].destChainId = params.dstChainId;

emit BridgeRequested({
transactionId: transactionId,
Expand Down Expand Up @@ -313,8 +314,7 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
// Update status to RELAYER_PROVED and store the proof details
// Note: these are storage writes
$.status = BridgeStatus.RELAYER_PROVED;
$.proofBlockTimestamp = uint40(block.timestamp);
$.proofBlockNumber = uint48(block.number);
$.proofBlockTimestamp = uint56(block.timestamp);
$.proofRelayer = relayer;

emit BridgeProofProvided(transactionId, relayer, destTxHash);
Expand All @@ -328,7 +328,7 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
// Aggregate the read operations from the same storage slot
address proofRelayer = $.proofRelayer;
BridgeStatus status = $.status;
uint40 proofBlockTimestamp = $.proofBlockTimestamp;
uint56 proofBlockTimestamp = $.proofBlockTimestamp;

// Can only claim a RELAYER_PROVED transaction after the dispute period
if (status != BridgeStatus.RELAYER_PROVED) revert StatusIncorrect();
Expand Down Expand Up @@ -425,14 +425,14 @@ contract FastBridgeV2 is Admin, MulticallTarget, IFastBridgeV2, IFastBridgeV2Err
}

/// @notice Calculates time since proof submitted
/// @dev proof.timestamp stores casted uint40(block.timestamp) block timestamps for gas optimization
/// _timeSince(proof) can accomodate rollover case when block.timestamp > type(uint40).max but
/// proof.timestamp < type(uint40).max via unchecked statement
/// @dev proof.timestamp stores casted uint56(block.timestamp) block timestamps for gas optimization
/// _timeSince(proof) can accomodate rollover case when block.timestamp > type(uint56).max but
/// proof.timestamp < type(uint56).max via unchecked statement
/// @param proofBlockTimestamp The bridge proof block timestamp
/// @return delta Time delta since proof submitted
function _timeSince(uint40 proofBlockTimestamp) internal view returns (uint256 delta) {
function _timeSince(uint56 proofBlockTimestamp) internal view returns (uint256 delta) {
unchecked {
delta = uint40(block.timestamp) - proofBlockTimestamp;
delta = uint56(block.timestamp) - proofBlockTimestamp;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ interface IFastBridgeV2 is IFastBridge {

struct BridgeTxDetails {
BridgeStatus status;
uint40 proofBlockTimestamp;
uint48 proofBlockNumber;
uint32 destChainId;
uint56 proofBlockTimestamp;
address proofRelayer;
}

Expand Down
Loading

0 comments on commit 5e11d4d

Please sign in to comment.