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

Sitvanit/add curve #14

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Sitvanit/add curve #14

wants to merge 12 commits into from

Conversation

sitvanit83
Copy link
Contributor

Add contract Curve with 2 specs: regular rule and builtin rule. This is using the munge version.

@sitvanit83 sitvanit83 requested a review from shellygr July 17, 2023 11:02
Copy link
Contributor

@shellygr shellygr left a comment

Choose a reason for hiding this comment

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

tried my best to check the solidity but would appreaciate another pair of eyes. there are still quite a lot of cleanups to do


#Curve

This directory contains the contract Curve which has the read only reentrancy weakness.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This directory contains the contract Curve which has the read only reentrancy weakness.
This directory contains the Curve contract which has the read only reentrancy weakness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done



##Specs
certora/specs contains two spec files for exposing this weakness.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
certora/specs contains two spec files for exposing this weakness.
`certora/specs` contains two spec files for exposing this weakness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

##Specs
certora/specs contains two spec files for exposing this weakness.

1. BuiltinViewReentrancy.spec uses the builtin rule viewReentrancy that checks that for every solidity function and every
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1. BuiltinViewReentrancy.spec uses the builtin rule viewReentrancy that checks that for every solidity function and every
1. `BuiltinViewReentrancy.spec` uses the builtin rule `viewReentrancy` that checks that for every Solidity function and every

changes of this style should be applied everywhere, not adding more comments on it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


1. BuiltinViewReentrancy.spec uses the builtin rule viewReentrancy that checks that for every solidity function and every
view function the read only reentrancy weakness is not present.
2. ViewReentrancy.spec uses regular rules for checking that for every solidity function but only for the view function
Copy link
Contributor

Choose a reason for hiding this comment

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

the sentence is not coherent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and now?

1. The value of getVirtualPrice() at the current state.
2. The value of getVirtualPrice() before the unresolved call present in the solidity function.
3. The value of getVirtualPrice() after the unresolved call present in the solidity function.
4. The existence of read only weakness with respect to getVirtualPrice().
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
4. The existence of read only weakness with respect to getVirtualPrice().
4. The existence of a read only weakness with respect to getVirtualPrice().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done




// constructor(uint256 _future_A_time, uint256 _future_A, uint256 _initial_A_time, uint256 _initial_A, address owner ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 ?

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

}


// function get_D(uint xp_0, uint xp_1)
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 ?

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

return xp[0] + xp[1];
// Simplification end

for (uint256 _x=0;_x<xp.length;_x++){
Copy link
Contributor

Choose a reason for hiding this comment

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

this is the original code and currently it's unreachable. it cleaner to just remove or comment out with a comment saying we simplified this function, and why it's okay in the context of read-only reentrancy checks

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess everything after the line 65 (return xp[0] + xp[1];) in this function is unreachable and redundant.

Copy link
Contributor Author

@sitvanit83 sitvanit83 Jul 17, 2023

Choose a reason for hiding this comment

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

Commented out but @DanieLion55 please review as you are the author.

// uint256 x;
// return _DEMO_D;
// return _DEMO_D_MAPPING[xp[0]][xp[1]][amp];
return xp[0] + xp[1];
Copy link
Contributor

Choose a reason for hiding this comment

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

not really unconstrained ghost...

Copy link
Contributor Author

@sitvanit83 sitvanit83 Jul 18, 2023

Choose a reason for hiding this comment

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

I guess you mean not unconstrained const. Removed from the comment.

uint256 S = 0;
uint256 Dprev = 0;
// Demo simplificaiton - unconstrained CONST
// get_D currently crashes the prover's pre-SMT analysis or something
Copy link
Contributor

Choose a reason for hiding this comment

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

we need to say that to reduce the running time of the example this function was simplified

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

function _A() view internal returns(uint256) {

// Demo simplificaiton - return unconstrained CONST
return future_A;
Copy link
Contributor

Choose a reason for hiding this comment

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

Everything in this function after this line is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commented out. Might be needed later for a better simplification.

revert();
}

function _A() view internal returns(uint256) {
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 should add some documentation for this function.
Also, I would prefer a more meaningful name than _A.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand the meaning of A, D and others. @DanieLion55 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A, D are the names from the original Curve so better leave them. I added comments on what I know.


// function get_D(uint xp_0, uint xp_1)

function get_D(uint256[2] memory xp,uint256 amp) public view returns(uint256) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add an explanation as to what this function does?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just commented on the symplification. I don't understand the original function. @DanieLion55 ?

Copy link

@DanieLion55 DanieLion55 left a comment

Choose a reason for hiding this comment

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

added some comments on the readme file.
I didn't find there the reference to which tests failed, can you be more specific?

CVLByExample/Curve/README.md Show resolved Hide resolved
CVLByExample/Curve/README.md Outdated Show resolved Hide resolved
CVLByExample/Curve/README.md Show resolved Hide resolved
CVLByExample/Curve/README.md Outdated Show resolved Hide resolved
@sitvanit83 sitvanit83 requested a review from DanieLion55 July 26, 2023 15:53
@sitvanit83 sitvanit83 requested a review from nd-certora July 27, 2023 08:57
f(e, data);
require after_func1 == getVirtualPrice(e_external);
assert cond;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is extremely hard to understand, lets wait for the summarization that can call solidity and it will be clean and easy to follow.
all this example should move under readonlyReentrancy folder

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.

5 participants