-
Notifications
You must be signed in to change notification settings - Fork 38
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
Liav/cert 7804 trusted methods #149
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"files": [ | ||
"./Example.sol:Example" | ||
], | ||
"process": "emv", | ||
"solc": "solc8.25", | ||
"verify": "Example:./trustedMethod.spec", | ||
"prover_resource_files": ["trustedMethods:ExampleTrustedMethods.json"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
contract Example{ | ||
address public constant foo = 0xE0f5206BBD039e7b0592d8918820024e2a7437b9; | ||
|
||
//We trust the contract address and the sighash | ||
function callTrusted() external returns (uint){ | ||
Foo bar = Foo(foo); | ||
return bar.trusted(); | ||
} | ||
|
||
//We trust the contract address, but not the sighash of the call. | ||
function callUntrusted() external returns (uint){ | ||
Foo bar = Foo(foo); | ||
return bar.untrusted(); | ||
} | ||
|
||
//We neither trust the sighash, nor the contract address. | ||
function callUntrusted(address userTrustedContractAddress) external returns (uint){ | ||
Foo bar = Foo(userTrustedContractAddress); | ||
return bar.untrusted(); | ||
} | ||
|
||
//We trust the sighash, but the contract address is unknown. | ||
function callUntrustedDespiteKnownSighash(address userTrustedContractAddress) external returns (uint){ | ||
Foo bar = Foo(userTrustedContractAddress); | ||
return bar.trusted(); | ||
} | ||
} | ||
|
||
contract Foo{ | ||
//Sighash: 0xb23d4266 | ||
function untrusted() external returns (uint){ | ||
return 1; | ||
} | ||
//Sighash: 0x7e2a6db8 | ||
function trusted() external returns (uint){ | ||
return 2; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
CVLByExample/TrustedMethodsAnalysis/ExampleTrustedMethods.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"0xe0f5206bbd039e7b0592d8918820024e2a7437b9": ["0x7e2a6db8"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Trusted Method Analysis | ||
|
||
This feature checks for external calls and checks the calls against an allow lists by specifying a new built in parametric rule: `use builtin rule trustedMethods`. | ||
|
||
The rule succeeds if all external calls are fully resolved (i.e. sighash and target) and are on the defined trusted methods list. Otherwise the analysis reports violated for this method. This entails that the rule fails as soon as there is any call that is unresolved due to a missing target or a missing unresolved sighash, for instance as the deployed contract requires linking. | ||
|
||
The allow list must be set via `"prover_resource_files": ["trustedMethods:ExampleTrustedMethods.json"]` in the config file. | ||
|
||
**How to specify custom trusted methods** | ||
|
||
You can use a different set of trusted methods by specifying your own `trustedMethod.json` file in the following format: | ||
``` | ||
{ | ||
"0xe0f5206bbd039e7b0592d8918820024e2a7437b9": ["0x4c6c6213","0x8f6462c3",...], | ||
"0xe918820024e2a7437b90f5206bbd039e7b0592d8": ["0x62134c6c","0x2c38f646",...] | ||
} | ||
``` | ||
And adding `"prover_resource_files": ["trustedMethods:trustedMethod.json"]` to the config file. | ||
|
||
It's also possible to define a wildcard for the contract address or for the method sighash by using "_". | ||
|
||
Run this example using: | ||
```certoraRun Example.conf``` | ||
[A report of this run](https://prover.certora.com/output/15800/4b6ef8f696284c839d772d6826b1b126?anonymousKey=7ebf992183ae4227631ec8e3df862a5d444dc552) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use builtin rule trustedMethods; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we show more complicated examples? I'm not sure what will happen when the resolution is via spec/smt:
for example: 1. passing the target as a parameter and having a dispatcher:
2. an unresolved call the we have a in the spec "unresolved call"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to play with this a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tried some things but I probably didn't fully understand you.
I mainly tried to add an example for a function that will call an arbitrary function on
Foo
and then have a dispatch list such that any unresolved calls in that function will go toFoo.trusted()
and this was the result.If that's important it would be helpful if you could elaborate a little bit about what you meant please :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johspaeth you might be able to help here 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a dispatcher is currently not expected to work here, the check is implemented as a built-in rule and these don't apply the CVL summaries at all. (Exactly as
use builtin rule sanity;
)The current use case we have is actually for byte code analysis to have a simple analysis that detects method calls that are to unknown target / unknown sighashes. If we have more use cases, we can change the logic and allow CVL summarization etc, for now I don't see this critical though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification @johspaeth 🙏