fix(purity): modify _submit
to check both initcode and runtime
#21
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.
This PR depends on #19
Overview
Contracts possess both a
creationCode
and aruntimeCode
. At a high level, it is the job of thecreationCode
to load theruntimeCode
into memory and then return it, in turn creating the contract. The_submit
function runs thePurityChecker
on thecreationCode
but not theruntimeCode
introducing two ways to include illegal opcodes in the final runtime.MSTORE8
.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 thecreationCode
since not checking the latter would allow for a solver to precompute the values in thecreationCode
itself since in_submit
the solution's deployment to_target
occurs in the same execution environment as the call torun
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 bothcreationCode
andruntimeCode
within_submit
.Fixes
CurtaGolf.sol
PurityChecker
to check against the solution's runtime (target.code
) in addition to the initcode, the_solution
param._solution
totarget
accordingly.