Skip to content

Commit

Permalink
Add deposit limit verification to L1ERC20Bridge and MailboxFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
juan518munoz committed Jan 25, 2024
1 parent 4567f2b commit 177f18e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions l1-contracts/contracts/bridge/L1ERC20Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ contract L1ERC20Bridge is IL1Bridge, IL1BridgeLegacy, ReentrancyGuard {
(amount, offset) = UnsafeBytes.readUint256(_l2ToL1message, offset);
}

/// @dev Verify the deposit limit is reached to its cap or not
function _verifyDepositLimit(address _l1Token, address _depositor, uint256 _amount, bool _claiming) internal {
IAllowList.Deposit memory limitData = IAllowList(allowList).getTokenDepositLimitData(_l1Token);
if (!limitData.depositLimitation) return; // no deposit limitation is placed for this token

if (_claiming) {
totalDepositedAmountPerUser[_l1Token][_depositor] -= _amount;
} else {
require(totalDepositedAmountPerUser[_l1Token][_depositor] + _amount <= limitData.depositCap, "d1");
totalDepositedAmountPerUser[_l1Token][_depositor] += _amount;
}
}

/// @return The L2 token address that would be minted for deposit of the given L1 token
function l2TokenAddress(address _l1Token) public view returns (address) {
bytes32 constructorInputHash = keccak256(abi.encode(l2TokenBeacon, ""));
Expand Down
9 changes: 9 additions & 0 deletions l1-contracts/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ contract MailboxFacet is Base, IMailbox {
);
}

/// @dev Verify the deposit limit is reached to its cap or not
function _verifyDepositLimit(address _l1Token, address _depositor, uint256 _amount) internal {
IAllowList.Deposit memory limitData = IAllowList(s.allowList).getTokenDepositLimitData(_l1Token);
if (!limitData.depositLimitation) return; // no deposit limitation is placed for this token

require(s.totalDepositedAmountPerUser[_l1Token][_depositor] + _amount <= limitData.depositCap, "d1");
s.totalDepositedAmountPerUser[_l1Token][_depositor] += _amount;
}

function _requestL2Transaction(
address _sender,
address _contractAddressL2,
Expand Down

0 comments on commit 177f18e

Please sign in to comment.