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

Bridge contracts: implement require(cond, error) pattern and update to solc 0.8.27 #852

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andygolay
Copy link
Contributor

Summary

Changelog

Update AtomicBridgeInitiatorMOVE.sol and AtomicBridgeCounterparty.sol` to use the require -> custom error pattern.

Testing

Solidity tests pass with forge test --fork-url https://ethereum-sepolia-rpc.publicnode.com -vv in protocol-units/bridge/contracts

Outstanding issues

@andygolay andygolay changed the title Bridge contracts: add require -> custom error pattern and update to solc 0.8.27 Bridge contracts: implement require -> custom error pattern and update to solc 0.8.27 Nov 13, 2024
@andygolay andygolay changed the title Bridge contracts: implement require -> custom error pattern and update to solc 0.8.27 Bridge contracts: implement require(cond, error) pattern and update to solc 0.8.27 Nov 13, 2024
Copy link

@franck44 franck44 left a comment

Choose a reason for hiding this comment

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

The scope of the issue is to fix input validation, and use the requires pattern for input validation.

Some of the proposed changes impact code that is not input validation and should not be changed to use requires.

@andygolay
Copy link
Contributor Author

The scope of the issue is to fix input validation, and use the requires pattern for input validation.

Some of the proposed changes impact code that is not input validation and should not be changed to use requires.

Thank you @franck44, I made the requested changes.

Copy link

@franck44 franck44 left a comment

Choose a reason for hiding this comment

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

Thanks @andygolay !

@Primata
Copy link
Contributor

Primata commented Nov 14, 2024

@franck44 I believe that if it's not a conditional logic flow, require should be used for consistency.
I think @andygolay could go back to using require on transfer checks.

@andygolay
Copy link
Contributor Author

andygolay commented Nov 14, 2024

@franck44 I believe that if it's not a conditional logic flow, require should be used for consistency. I think @andygolay could go back to using require on transfer checks.

Whatever you guys decide is okay with me; I did look it up and it seems like require is technically fine to use throughout, but it's conventionally used for input values. I wonder if that's because require used to be less gas efficient, so it was used sparingly? And maybe now conventions can shift to using require in general? It does strike me as more normalized syntax to use require for all checks that could revert with a custom error.

The first commit is with all require, the second is with require on input values only. I'll defer to the team as I don't have a strong opinion about it.

@franck44
Copy link

@0xPrimata

I believe that if it's not a conditional logic flow, require should be used for consistency.
I think @andygolay could go back to using require on transfer checks.

No, that's not best practice. I provided lots of documentation in issue 827, so we are going to follow best practice.

requires to validate inputs, and reverts for more complex errors.

We can merge this PR and close the issue.

@franck44
Copy link

@andygolay

I forgot to mention that there is another reason why requires are used for input validation but not for other revert conditions: requires act as pre-conditions i.e. conditions under which the function can be called. The requires are used by SMTChecker in the Solidity compiler as specifications to verify some properties of the functions.

@0xmovses 0xmovses marked this pull request as draft November 20, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bridge] [Solidity] Use require for input validation rather than if-revert pattern
4 participants