Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiOffRamp - size optimizations #991

Merged
merged 27 commits into from
Jun 21, 2024

Conversation

elatoskinas
Copy link
Contributor

@elatoskinas elatoskinas commented Jun 11, 2024

Motivation

Optimizes the contract size for the merged MultiOffRamp + CommitStore to be able to fit the deployment size limits

Solution

Currently the margin is at -0.972KB with 3600 optimizer runs. The contract size fits the space with 1800 optimizer runs.

The contract size can further be reduced, and the optimizer runs increased after the Nonce Manager is integrated into the MultiOffRamp

Each optimization is split into a separate commit. Complete list:

  • Remove in-depth message validations -> these will be moved off-chain (ticket already created)
  • Move isCursed to shared internal function
  • Move forked chain check, curse check and source config enabled check to common internal function
  • Move source chain config + curse check to single shared function (used in both exec & commit)
  • Move zero address check to internal lib
  • Remove global pausing from the multi-offramp -> there are 4 alternative methods of achieving pausing:
    • Per-lane: using IMessageValidator (execution-only), disabling the source chain config, cursing the lane via RMN
    • Globally: implementing the global pause in the RMN
    • The savings are significant, at around ~0.8KB
  • Split StaticConfig and DynamicConfig set events
  • Get rid of Any2EVMMessageRoute and use 2 internal functions to solve stack depth (same as the OffRamp changes)
  • Other contract size golfing: variable caching, inlining
  • Compile with lower optimizer runs for the multi-offramp
  • Update: OCR3 no longer needs a uniqueReports distinction
  • Other fix: OCR3 now uses sequenceNumbers

Copy link
Contributor

I see you updated files related to contracts. Please run pnpm changeset in the contracts directory to add a changeset.

Copy link
Contributor

Go solidity wrappers are out-of-date, regenerate them via the make wrappers-all command

Copy link
Contributor

github-actions bot commented Jun 11, 2024

LCOV of commit bc9743a during Solidity Foundry #5617

Summary coverage rate:
  lines......: 98.8% (1460 of 1477 lines)
  functions..: 96.0% (289 of 301 functions)
  branches...: 92.9% (619 of 666 branches)

Files changed coverage rate: n/a

@elatoskinas elatoskinas marked this pull request as ready for review June 11, 2024 11:48
@elatoskinas elatoskinas requested review from makramkd and a team as code owners June 11, 2024 11:48
@elatoskinas elatoskinas added the do not merge Do not merge at this time label Jun 11, 2024
Base automatically changed from feat/merged-multi-ramp to ccip-develop June 13, 2024 11:42
@elatoskinas elatoskinas requested review from RayXpub and a team as code owners June 13, 2024 11:42
@@ -181,6 +182,10 @@ library Internal {
return address(uint160(encodedAddress));
}

function _validateNonZeroAddress(address inputAddress) internal pure {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly not super fan of this as it makes the calls with multiple zero checks pretty unreadable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this. The overhead is 0.056KB without the optimization, but I agree regarding the readability

/// @dev Whether this OffRamp is paused or not
bool private s_paused = false;
/// @dev The sequence number of the last report
uint64 private s_latestPriceSequenceNumber;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we still need the separate price seq num? Are these always sequencial without any gaps in OCR3? If so, we could force strict ordering based on seqNums?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Creating a separate ticket for this

Copy link
Collaborator

@RensR RensR left a comment

Choose a reason for hiding this comment

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

Approved pending zero check undo and let's continue the discussion on potential OCR3 seq num improvements

@elatoskinas elatoskinas force-pushed the feat/merged-ramp-size-optimizations branch from 92028ed to c42f37d Compare June 20, 2024 15:21
@elatoskinas elatoskinas merged commit 969d44a into ccip-develop Jun 21, 2024
80 checks passed
@elatoskinas elatoskinas deleted the feat/merged-ramp-size-optimizations branch June 21, 2024 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants