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

[Tracker] EVM Engineering: solidity code coverage #11093

Open
Tracked by #12703
tynes opened this issue Jul 8, 2024 · 3 comments · May be fixed by #12843
Open
Tracked by #12703

[Tracker] EVM Engineering: solidity code coverage #11093

tynes opened this issue Jul 8, 2024 · 3 comments · May be fixed by #12843
Assignees

Comments

@tynes
Copy link
Contributor

tynes commented Jul 8, 2024

It would be ideal to have some form of code coverage for the solidity code that is reliable. Foundry does have code coverage, but we hit stack too deep issues when compiling for it (because it turns optimizations off). This means that we do not have any form of reliable code coverage right now for the solidity contracts. This results in a lot of extra work for devs doing code review - they must manually check that code paths have been covered.

Once we fix the ability to use foundry code coverage, we could set something up like what uniswap v4 uses. https://github.com/Uniswap/v4-core/blob/main/.github/workflows/coverage.yml. It is a simple github action that automatically posts the outputs of forge coverage into a github comment on a pull request.

@iainnash
Copy link

Forge forge coverage has a --minimal-ir option that allows some optimizations at the cost of potentially breaking source maps in some places.

@mds1
Copy link
Contributor

mds1 commented Aug 9, 2024

We also get stack too deep when compiling with via-ir, so the --ir-minimum will not work for us. (More info in ethereum/solidity#14358 (comment), I believe even when marking blocks assembly-safe we still get the issue)

Since coverage maps are still not ideal with via-ir, the best solution here is to just fix all stack too deep sources so we can compile with no optimizer. Below is a snippet that will list all contracts that fail to compile due to stack too deep:

while IFS= read -r -d '' file; do
  solc $(forge re) "$file" --bin 2>&1 | grep -q "Stack too deep"
  if [ $? -eq 0 ]; then
    echo "Stack too deep error found in $file"
  fi
done < <(find . -type f -name "*.sol" -print0)

Most contracts that get listed are because a contract they inherit from (like Deploy and LibKeccak IIRC) has stack too deep itself, so in reality its probably <5 contracts to fix. What I mean is, given:

contract A { /*compiles ok */ }
contract B is A { /* stack too deep */ }
contract C is B { /* stack too deep */ }

the above snippet will output

Stack too deep error found in B.sol
Stack too deep error found in C.sol

But in reality, we most likely only need to fix B.sol, as it's the cause of the stack too deep in C as well

@tynes tynes moved this to Backlog in EVM Engineering Aug 30, 2024
@smartcontracts smartcontracts changed the title Solidity Code Coverage EVM Engineering: solidity code coverage Aug 30, 2024
@smartcontracts smartcontracts changed the title EVM Engineering: solidity code coverage [Tracker] EVM Engineering: solidity code coverage Aug 30, 2024
@AmadiMichael
Copy link
Member

AmadiMichael commented Nov 5, 2024

I'll take on this cc @smartcontracts can this get assigned to me?

@AmadiMichael AmadiMichael self-assigned this Nov 5, 2024
@smartcontracts smartcontracts moved this from Backlog to TO-DO in EVM Engineering Nov 5, 2024
@AmadiMichael AmadiMichael linked a pull request Nov 6, 2024 that will close this issue
@AmadiMichael AmadiMichael moved this from In progress to In review in Proofs team - Project Delivery tracking board Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging a pull request may close this issue.

4 participants