Skip to content

Commit

Permalink
+tests, zeroAddr check, fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
parodime committed Sep 25, 2024
1 parent 41b552c commit 3f2f3da
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
18 changes: 8 additions & 10 deletions packages/contracts-rfq/contracts/FastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,19 @@ contract FastBridgeV2 is Admin, IFastBridgeV2 {

/// @inheritdoc IFastBridgeV2
function relay(bytes memory request, address relayer) public payable {
if (relayer == address(0)) revert ZeroAddress();
bytes32 transactionId = keccak256(request);
BridgeTransaction memory transaction = getBridgeTransaction(request);
if (transaction.destChainId != uint32(block.chainid)) revert ChainIncorrect();

// check haven't exceeded deadline for relay to happen
if (block.timestamp > transaction.deadline) revert DeadlineExceeded();

if (bridgeRelayDetails[transactionId].relayer != address(0)) revert TransactionRelayed();

// mark bridge transaction as relayed
if (bridgeRelayDetails[transactionId].blockNumber != 0) revert TransactionRelayed();

bridgeRelayDetails[transactionId] = BridgeRelay({
blockNumber: uint48(block.number),
blockTimestamp: uint48(block.timestamp),
relayer: relayer
});
bridgeRelayDetails[transactionId] =
BridgeRelay({blockNumber: uint48(block.number), blockTimestamp: uint48(block.timestamp), relayer: relayer});

// transfer tokens to recipient on destination chain and gas rebate if requested
address to = transaction.destRecipient;
Expand Down Expand Up @@ -178,11 +176,11 @@ contract FastBridgeV2 is Admin, IFastBridgeV2 {
rebate
);
}

/// @inheritdoc IFastBridgeV2
function bridgeRelays(bytes32 transactionId) external view returns (bool) {
function bridgeRelays(bytes32 transactionId) public view returns (bool) {
// has this transactionId been relayed?
return bridgeRelayDetails[transactionId].blockNumber != 0;
return bridgeRelayDetails[transactionId].relayer != address(0);
}

Check notice

Code scanning / Slither

Block timestamp Low


/// @inheritdoc IFastBridge
Expand Down
2 changes: 0 additions & 2 deletions packages/contracts-rfq/contracts/interfaces/IFastBridgeV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.20;
import {IFastBridge} from "./IFastBridge.sol";

interface IFastBridgeV2 is IFastBridge {

/// @notice Relays destination side of bridge transaction by off-chain relayer
/// @param request The encoded bridge transaction to relay on destination chain
/// @param relayer The address of the relaying entity which should have control of the origin funds when claimed
Expand All @@ -30,5 +29,4 @@ interface IFastBridgeV2 is IFastBridge {
uint48 blockTimestamp;
address relayer;
}

}
22 changes: 21 additions & 1 deletion packages/contracts-rfq/test/FastBridgeV2.Dst.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ChainIncorrect, DeadlineExceeded, TransactionRelayed} from "../contracts/libs/Errors.sol";
import {ChainIncorrect, DeadlineExceeded, TransactionRelayed, ZeroAddress} from "../contracts/libs/Errors.sol";

import {FastBridgeV2, FastBridgeV2Test, IFastBridge} from "./FastBridgeV2.t.sol";

Expand Down Expand Up @@ -115,6 +115,21 @@ contract FastBridgeV2DstTest is FastBridgeV2Test {
assertEq(address(fastBridge).balance, 0);
}

/// @notice RelayerB completes the ETH bridge request, using relayerA's address
function test_relay_eth_withRelayerAddress_checkBlockData() public {
vm.roll(987_654_321);
vm.warp(123_456_789);
bytes32 txId = getTxId(ethTx);
expectBridgeRelayed(ethTx, txId, address(relayerA));
relayWithAddress({caller: relayerB, relayer: relayerA, msgValue: ethParams.destAmount, bridgeTx: ethTx});
assertTrue(fastBridge.bridgeRelays(txId));
(uint48 recordedBlockNumber, uint48 recordedblockTimestamp,) = fastBridge.bridgeRelayDetails(txId);
assertEq(recordedBlockNumber, 987_654_321);
assertEq(recordedblockTimestamp, 123_456_789);
assertEq(address(userB).balance, ethParams.destAmount);
assertEq(address(relayerB).balance, LEFTOVER_BALANCE);
assertEq(address(fastBridge).balance, 0);
}
// ══════════════════════════════════════════════════ REVERTS ══════════════════════════════════════════════════════

function test_relay_revert_chainIncorrect() public {
Expand Down Expand Up @@ -152,4 +167,9 @@ contract FastBridgeV2DstTest is FastBridgeV2Test {
vm.expectRevert(DeadlineExceeded.selector);
relayWithAddress({caller: relayerA, relayer: relayerB, msgValue: 0, bridgeTx: tokenTx});
}

function test_relay_withRelayerAddress_revert_zeroAddr() public {
vm.expectRevert(ZeroAddress.selector);
relayWithAddress({caller: relayerA, relayer: address(0), msgValue: 0, bridgeTx: tokenTx});
}
}

0 comments on commit 3f2f3da

Please sign in to comment.