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

Revert custom errors to require statements #59

Merged
merged 24 commits into from
Oct 19, 2023

Conversation

minghinmatthewlam
Copy link

@minghinmatthewlam minghinmatthewlam commented Oct 16, 2023

Why this should be merged

We want to move back from custom errors to require statements because certain toolings are not compatible well with custom errors yet, for example snow trace, or when forge tests fail they're show a hash that needs to be decoded with the abi to be readable. This will cause an increase in contract size and deployment costs but the tradeoff is for easier debugging and integration with existing tools.

How this works

  • Removes the custom errors in all contracts
  • Replace custom error checks by inverting if statements and using require statements in the form "{contract}: {error message}"
  • Updates solhint config to have maximum reason string of 60, and turns off for custom errors
  • Add scripts/local/lint.sh script
  • Removes redundant teleporter messenger sender checks for functions called by receiveTeleporterMessage

How this was tested

  • updating unit tests
  • ci

BEFORE gas report:

| src/Teleporter/TeleporterMessenger.sol:TeleporterMessenger contract |                 |        |        |        |         |
|---------------------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost                                                     | Deployment Size |        |        |        |         |
| 2174481                                                             | 10854           |        |        |        |         |
| Function Name                                                       | min             | avg    | median | max    | # calls |
| addFeeAmount                                                        | 3486            | 5545   | 4070   | 9507   | 7       |
| checkIsAllowedRelayer                                               | 950             | 1121   | 950    | 1643   | 5       |
| checkRelayerRewardAmount                                            | 764             | 764    | 764    | 764    | 8       |
| getFeeInfo                                                          | 851             | 1651   | 851    | 4851   | 5       |
| getMessageHash                                                      | 643             | 928    | 643    | 2643   | 7       |
| getNextMessageID                                                    | 660             | 1993   | 2660   | 2660   | 3       |
| getReceiptAtIndex                                                   | 903             | 1038   | 903    | 1616   | 21      |
| getReceiptQueueSize                                                 | 730             | 3896   | 4730   | 4730   | 24      |
| getRelayerRewardAddress                                             | 629             | 754    | 629    | 2629   | 16      |
| messageReceived                                                     | 673             | 839    | 673    | 2673   | 12      |
| receiveCrossChainMessage                                            | 609             | 87978  | 101991 | 178925 | 51      |
| redeemRelayerRewards                                                | 1946            | 2230   | 2008   | 2736   | 3       |
| retryMessageExecution                                               | 3748            | 16726  | 9318   | 57861  | 11      |
| retryReceipts                                                       | 8634            | 37784  | 40410  | 64310  | 3       |
| retrySendCrossChainMessage                                          | 5440            | 7799   | 7753   | 10206  | 3       |
| sendCrossChainMessage                                               | 34540           | 101038 | 111478 | 137275 | 32      |

AFTER gas report:

| src/Teleporter/TeleporterMessenger.sol:TeleporterMessenger contract |                 |        |        |        |         |
|---------------------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost                                                     | Deployment Size |        |        |        |         |
| 2410954                                                             | 12035           |        |        |        |         |
| Function Name                                                       | min             | avg    | median | max    | # calls |
| addFeeAmount                                                        | 3553            | 5606   | 4142   | 9497   | 7       |
| checkIsAllowedRelayer                                               | 950             | 1121   | 950    | 1643   | 5       |
| checkRelayerRewardAmount                                            | 764             | 764    | 764    | 764    | 8       |
| getFeeInfo                                                          | 851             | 1651   | 851    | 4851   | 5       |
| getMessageHash                                                      | 643             | 928    | 643    | 2643   | 7       |
| getNextMessageID                                                    | 660             | 1993   | 2660   | 2660   | 3       |
| getReceiptAtIndex                                                   | 903             | 1045   | 903    | 1616   | 20      |
| getReceiptQueueSize                                                 | 730             | 3860   | 4730   | 4730   | 23      |
| getRelayerRewardAddress                                             | 629             | 754    | 629    | 2629   | 16      |
| messageReceived                                                     | 673             | 839    | 673    | 2673   | 12      |
| receiveCrossChainMessage                                            | 609             | 87993  | 101991 | 178925 | 51      |
| redeemRelayerRewards                                                | 1946            | 2262   | 2016   | 2826   | 3       |
| retryMessageExecution                                               | 3859            | 16787  | 9380   | 57861  | 11      |
| retryReceipts                                                       | 8724            | 37814  | 40410  | 64310  | 3       |
| retrySendCrossChainMessage                                          | 5551            | 7873   | 7864   | 10206  | 3       |
| sendCrossChainMessage                                               | 34651           | 101042 | 111478 | 137275 | 32      |

Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

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

There are two msg.sender checks that were removed that I didn't see earlier. Just want to confirm that they are no longer necessary.

revert InsufficientTotalAmount(totalAmount, primaryFeeAmount + secondaryFeeAmount);
}
require(
totalAmount >= primaryFeeAmount + secondaryFeeAmount,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be > not >=

Copy link
Author

Choose a reason for hiding this comment

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

is this to avoid us calling encodeMintBridgeTokensData with 0 bridge amount? Should we add a check in mint that the amount != 0 if this is the case?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The check in mint would be in the transaction receiving the Teleporter message, rather than the one sending it here. The idea being that the amount bridged excluding fees must be non-zero.

contracts/src/Teleporter/TeleporterMessenger.sol Outdated Show resolved Hide resolved
scripts/local/lint.sh Outdated Show resolved Hide resolved
Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

A couple of minor comments, but overall LGTM

scripts/local/lint.sh Show resolved Hide resolved
@@ -24,5 +24,4 @@ jobs:
# in subdirectories. The former only checks sol files in the current directory and directories one level down.
- name: Run Lint
run: |
cd contracts/src
npx solhint '**/*.sol' --config ./.solhint.json --ignore-path ./.solhintignore --max-warnings 0
./scripts/local/lint.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to either cd contracts/src or modify the script to point to TELEPORTER_PATH/contracts/src/.solhint.json

Copy link
Author

Choose a reason for hiding this comment

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

yup the lint script has cd $TELEPORTER_PATH/contracts/src. Lint workflow was failing because of installing locally, and script using solhint without npx. Looking online, when installing to use for command line we should install globally. https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I missed that cd. Nice find

Copy link
Contributor

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

👍

@minghinmatthewlam minghinmatthewlam merged commit 63e7132 into main Oct 19, 2023
@minghinmatthewlam minghinmatthewlam deleted the revert-custom-errors branch October 19, 2023 22:17
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.

4 participants