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

Refactor input validation #45

Closed
wants to merge 2 commits into from
Closed

Conversation

QGarchery
Copy link
Contributor

No description provided.

@QGarchery QGarchery self-assigned this Jul 5, 2023
@@ -60,18 +55,16 @@ contract Blue {
// Markets management.

function createMarket(Market calldata market) external {
Id id = market.toId();
Id id = Id.wrap(keccak256(abi.encode(market)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Annoying that we have to do that, but this solution ensures that we cannot miss the input validation of id

Copy link
Contributor

Choose a reason for hiding this comment

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

Did not see that my changes were already merged lol

Copy link
Contributor

Choose a reason for hiding this comment

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

why not externalizing the logic? Keeping toId as it was and creating a specific function for the input check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to ensure that we cannot miss the input validation of id: when you externalize the logic then it's easy to use the wrong function and not do the require on the id

@MathisGD
Copy link
Contributor

MathisGD commented Jul 5, 2023

I don't like it, for the same arguments exposed here: #38 (comment)

@@ -60,18 +55,16 @@ contract Blue {
// Markets management.

function createMarket(Market calldata market) external {
Id id = market.toId();
Id id = Id.wrap(keccak256(abi.encode(market)));
Copy link
Contributor

Choose a reason for hiding this comment

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

Did not see that my changes were already merged lol

@@ -60,18 +55,16 @@ contract Blue {
// Markets management.

function createMarket(Market calldata market) external {
Id id = market.toId();
Id id = Id.wrap(keccak256(abi.encode(market)));
Copy link
Contributor

Choose a reason for hiding this comment

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

why not externalizing the logic? Keeping toId as it was and creating a specific function for the input check?


// Input validation

modifier nonZero(uint amount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put the modifier at the top of the contract instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The idea was to group the input validation functions, we want them to look for them easily

@QGarchery
Copy link
Contributor Author

QGarchery commented Jul 5, 2023

I don't like it, for the same arguments exposed here: #38 (comment)

I don't think they apply here: the functions do things that are clearly defined. The toId function computes the id and validates it. The nonZero modifer does just what its name suggests.

The benefits are that we don't risk missing to validate the id, and that we ensure that the revert strings are the same for the same revert causes

@MathisGD
Copy link
Contributor

MathisGD commented Jul 5, 2023

For the nonZero yes you're right, but not for the toId. Named something like toExistingId or something similar would be more ok though.

@MathisGD
Copy link
Contributor

MathisGD commented Jul 5, 2023

The benefits are that we don't risk missing to validate the id, and that we ensure that the revert strings are the same for the same revert causes

This kind of things are very easy to test and prove, that's why I prefer maximizing the readability (for the rest of the logic, that is less trivial).

@QGarchery
Copy link
Contributor Author

This kind of things are very easy to test and prove, that's why I prefer maximizing the readability (for the rest of the logic, that is less trivial).

The concern about the current way it's tested is that we may forget to update them. But yes I agree, it's not a big deal, I just find it a bit more elegant to not have to repeat literal values like "unknown market" and "zero amount"

@MathisGD
Copy link
Contributor

MathisGD commented Jul 5, 2023

I prefer it like that. The nonZero amount is not really useful to me then though.

@QGarchery
Copy link
Contributor Author

Closing this because maybe it's not that useful to have only one input validation

@QGarchery QGarchery closed this Jul 7, 2023
@MerlinEgalite
Copy link
Contributor

Sorry seems to late, but I think this is still an interesting idea, maybe we can reopen the PR later on?

@MathisGD MathisGD deleted the refactor/input-validation branch July 7, 2023 14:14
@QGarchery QGarchery mentioned this pull request Jul 10, 2023
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