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

fix(purity): modify _submit to check both initcode and runtime #21

Merged
merged 3 commits into from
Jan 19, 2024

Conversation

Sabnock01
Copy link
Member

@Sabnock01 Sabnock01 commented Dec 19, 2023

This PR depends on #19

Overview

Contracts possess both a creationCode and a runtimeCode. At a high level, it is the job of the creationCode to load the runtimeCode into memory and then return it, in turn creating the contract. The _submit function runs the PurityChecker on the creationCode but not the runtimeCode introducing two ways to include illegal opcodes in the final runtime.

  1. First, illegal opcodes could be arithmetically computed and then stored in memory using MSTORE8.
  2. Second, the PurityChecker does not iterate over the bytes after pushes and instead increments the offset by the appropriate number of bytes and continues iteration. This makes it possible to push values to the stack that contain the illegal opcodes which then may be stored in memory.

It is not simply enough to check the runtimeCode and not the creationCode since not checking the latter would allow for a solver to precompute the values in the creationCode itself since in _submit the solution's deployment to _target occurs in the same execution environment as the call to run on the challenge. Since we don't want to sacrifice UX by separating these into different transactions, for a total of three for the solver to submit, we've opted to check both creationCode and runtimeCode within _submit.

Fixes

CurtaGolf.sol

  • Modifies the call to the PurityChecker to check against the solution's runtime (target.code) in addition to the initcode, the _solution param.
  • This check has thus been moved from before to after the deployment of _solution to target accordingly.

@Sabnock01 Sabnock01 marked this pull request as ready for review December 19, 2023 17:46
@Sabnock01 Sabnock01 changed the title fix(purity): modify _submit to check runtime instead of initcode fix(purity): modify _submit to check both initcode and runtime Dec 23, 2023
@Sabnock01 Sabnock01 merged commit 68ea826 into main Jan 19, 2024
1 check passed
@fiveoutofnine fiveoutofnine deleted the sabnock/check-runtime-purity branch February 22, 2024 23:46
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.

1 participant