Skip to content

Commit

Permalink
Fix Bridge Precision Restriction (MystenLabs#18063)
Browse files Browse the repository at this point in the history
## Description 

Currently only the depositERC20 checks that the conversion is greater
than 0. Moving the requirement to the conversion function itself to
capture both ERC20 and ETH deposits

## Test plan 

Added unit test coverage to account for both depositEth and depositERC20
  • Loading branch information
Bridgerz authored Jun 4, 2024
1 parent 86190d3 commit 07674e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 0 additions & 2 deletions bridge/evm/contracts/SuiBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ contract SuiBridge is ISuiBridge, CommitteeUpgradeable, PausableUpgradeable {
amountTransfered
);

require(suiAdjustedAmount > 0, "SuiBridge: Invalid amount provided");

emit TokensDeposited(
config.chainID(),
nonces[BridgeUtils.TOKEN_TRANSFER],
Expand Down
3 changes: 3 additions & 0 deletions bridge/evm/contracts/utils/BridgeUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ library BridgeUtils {
// Ensure the converted amount fits within uint64
require(amount <= type(uint64).max, "BridgeUtils: Amount too large for uint64");

// Ensure the converted amount is greater than 0
require(amount > 0, "BridgeUtils: Insufficient amount provided");

return uint64(amount);
}

Expand Down
9 changes: 7 additions & 2 deletions bridge/evm/test/SuiBridgeTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,17 @@ contract SuiBridgeTest is BridgeBaseTest, ISuiBridge {
reentrantAttack.attack();
}

function testSuiBridgeInvalidDecimalConversion() public {
function testSuiBridgeInvalidERC20DecimalConversion() public {
IERC20(wETH).approve(address(bridge), 10 ether);
vm.expectRevert(bytes("SuiBridge: Invalid amount provided"));
vm.expectRevert(bytes("BridgeUtils: Insufficient amount provided"));
bridge.bridgeERC20(BridgeUtils.ETH, 1, abi.encode("suiAddress"), 0);
}

function testSuiBridgeInvalidEthDecimalConversion() public {
vm.expectRevert(bytes("BridgeUtils: Insufficient amount provided"));
bridge.bridgeETH{value: 1}(abi.encode("suiAddress"), 0);
}

// An e2e token transfer regression test covering message ser/de and signature verification
function testTransferSuiToEthRegressionTest() public {
address[] memory _committee = new address[](4);
Expand Down

0 comments on commit 07674e0

Please sign in to comment.