From 68ea826c0214ffba9fbf5026dff33820e6d25b13 Mon Sep 17 00:00:00 2001 From: Sabnock <24715302+Sabnock01@users.noreply.github.com> Date: Thu, 18 Jan 2024 23:51:33 -0600 Subject: [PATCH] fix(purity): modify `_submit` to check both initcode and runtime (#21) * fix: check runtime in _submit * fix: add back initcode check --- src/CurtaGolf.sol | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/CurtaGolf.sol b/src/CurtaGolf.sol index ef59775..0a4711a 100644 --- a/src/CurtaGolf.sol +++ b/src/CurtaGolf.sol @@ -183,7 +183,7 @@ contract CurtaGolf is ICurtaGolf, KingERC721, Owned { // Revert if the course does not exist. if (address(courseData.course) == address(0)) revert CourseDoesNotExist(_courseId); - // Revert if the solution contains invalid opcodes. + // Revert if the initcode contains invalid opcodes. if (!purityChecker.check(_solution, getAllowedOpcodes[_courseId])) { revert PollutedSolution(); } @@ -194,6 +194,11 @@ contract CurtaGolf is ICurtaGolf, KingERC721, Owned { target := create(0, add(_solution, 0x20), mload(_solution)) } + // Revert if the runtime contains invalid opcodes. + if (!purityChecker.check(target.code, getAllowedOpcodes[_courseId])) { + revert PollutedSolution(); + } + // Run solution and mint NFT if it beats the leading score. uint32 gasUsed = courseData.course.run(target, block.prevrandao); if (courseData.gasUsed == 0 || gasUsed < courseData.gasUsed) {