Skip to content

Implement Rate Limiter Contract - #851

Closed
0xmovses wants to merge 9 commits into
mainfrom
0xmovses/rate-limiter
Closed

Implement Rate Limiter Contract#851
0xmovses wants to merge 9 commits into
mainfrom
0xmovses/rate-limiter

Conversation

@0xmovses

@0xmovses 0xmovses commented Nov 13, 2024

Copy link
Copy Markdown
Contributor

Summary

For a full spec please read MIP-56

Changelog

  • Creates RateLimiter.sol
  • Integrates RateLimiter into Initiator and Counterparty contracts

Testing

Adds the solidity unit test testRateLimitExceeded for both Initiator and Counterparty Contracts
cd protocol-units/bridge/contracts && forge test

Outstanding issues

Integration tests with the relayer should be added in a separate PR, more solidity unit tests could be added to test out the RateLimiter.sol

@0xmovses
0xmovses marked this pull request as draft November 13, 2024 16:09
@0xmovses 0xmovses self-assigned this Nov 13, 2024
@bhenhsi bhenhsi linked an issue Nov 13, 2024 that may be closed by this pull request
@0xmovses
0xmovses marked this pull request as ready for review November 14, 2024 13:28
@0xmovses
0xmovses requested review from Primata and apenzk November 14, 2024 13:28
}

// Private function to update the rate limits based on the security fund and risk period
function _updateRateLimits() private {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct, but choice of representation here and in MIP is funny. I think the MIP should express this more clearly, i.e., use $\frac{\text{securityFund}}{2 * \text{riskPeriod}}$

// Deploy and initialize the RateLimiter contract
rateLimiter = new RateLimiter();
uint256 riskPeriod = 24 * 60 * 60; // 24 hours in seconds
uint256 securityFund = 5 ether;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to be clear about MOVE token units here and in runbooks.

// Expect the second transfer to exceed the rate limit and revert
vm.expectRevert("RATE_LIMIT_EXCEEDED");
atomicBridgeCounterpartyMOVE.lockBridgeTransfer(
initiator,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'd like to see tests demonstrating both the L1->L2 direction and the L2->L1 direction.
  2. For user experience, L1->L2 should be able to revert on initiateBridgeTransfer, no?
  3. In general, why don't we use the bridgeTransferId returned by initiate?

@l-monninger

Copy link
Copy Markdown
Contributor

@0xmovses is there a good way to test this e2e? Or, should we trust in the forge ~sim and reserve the rest for our time working on operational bits?

@0xmovses

Copy link
Copy Markdown
Contributor Author

@l-monninger e2e will happen in another PR after #690 goes in.

@l-monninger

Copy link
Copy Markdown
Contributor

I know this is implemented for the Bilbao Model, but ideally we don't have to report the insurance fund balance and it can instead be queried on-chain. Even if it's just an account, as long as we know the account we can call balanceOf to determine how much it can ensure.

@0xmovses

Copy link
Copy Markdown
Contributor Author

@l-monninger sounds good.

@franck44 franck44 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may use require for input validation.
We have already modified the code to use requires in another (pending) PR so would be good to fix for consistency.
There are only a few instances to fix, so that should be an easy modification.

address owner,
uint256 _timeLockDuration
) public initializer {
if (_atomicBridgeInitiator == address(0)) revert ZeroAddress();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is input validation and should be written as:

require(_AtomicBridgeInitiator != address(0), ZeroAddress());

uint256 _timeLockDuration
) public initializer {
if (_atomicBridgeInitiator == address(0)) revert ZeroAddress();
if (_rateLimiter == address(0)) revert ZeroAddress();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input validation:

require (_rateLimiter != address(0), ZeroAddress());

}

function setRateLimiter(address _rateLimiter) external onlyOwner {
if (_rateLimiter == address(0)) revert ZeroAddress();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to:

require (_rateLimiter != address(0), ZeroAddress());

revert ZeroAddress();
}
if (_moveToken == address(0)) revert ZeroAddress();
if (_rateLimiter == address(0)) revert ZeroAddress();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input validation:

require (_rateLimiter != address(0), ZeroAddress());

@0xmovses 0xmovses closed this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate Limit Bridge

3 participants