From 7d61639307c02473afc85d9eabd2c154ae42422a Mon Sep 17 00:00:00 2001 From: Sabnock <24715302+Sabnock01@users.noreply.github.com> Date: Thu, 18 Jan 2024 23:50:22 -0600 Subject: [PATCH] fix: remove submitDirectly (#20) --- script/metadata/PrintKingArt.s.sol | 10 ++- script/metadata/PrintParArt.s.sol | 3 +- src/CurtaGolf.sol | 8 -- src/interfaces/ICurtaGolf.sol | 11 --- test/CurtaGolf.t.sol | 134 +---------------------------- 5 files changed, 15 insertions(+), 151 deletions(-) diff --git a/script/metadata/PrintKingArt.s.sol b/script/metadata/PrintKingArt.s.sol index 5cf1cff..d54812d 100644 --- a/script/metadata/PrintKingArt.s.sol +++ b/script/metadata/PrintKingArt.s.sol @@ -12,11 +12,19 @@ import { BaseTest } from "test/utils/BaseTest.sol"; /// tokens, as outputted by {KingArt}. /// @dev Must be compiled with `--via-ir` to avoid stack too deep errors. contract PrintKingArtScript is BaseTest, Script { + // ------------------------------------------------------------------------- + // Constants + // ------------------------------------------------------------------------- + + /// @notice The address of the recipient of the solution. + address constant RECIPIENT = 0xA85572Cd96f1643458f17340b6f0D6549Af482F5; + function setUp() public override { super.setUp(); // Submit a solution to course #1 as `fiveoutofnine.eth`. - curtaGolf.submitDirectly(1, EFFICIENT_SOLUTION, 0xA85572Cd96f1643458f17340b6f0D6549Af482F5); + curtaGolf.commit(keccak256(abi.encode(RECIPIENT, EFFICIENT_SOLUTION, 0))); + curtaGolf.submit(1, EFFICIENT_SOLUTION, RECIPIENT, 0); } // ------------------------------------------------------------------------- // `run` diff --git a/script/metadata/PrintParArt.s.sol b/script/metadata/PrintParArt.s.sol index 313b092..e021f1f 100644 --- a/script/metadata/PrintParArt.s.sol +++ b/script/metadata/PrintParArt.s.sol @@ -21,7 +21,8 @@ contract PrintParArtScript is BaseTest, Script { super.setUp(); // Submit a solution to course #1 as `RECIPIENT`. - curtaGolf.submitDirectly(1, EFFICIENT_SOLUTION, RECIPIENT); + curtaGolf.commit(keccak256(abi.encode(RECIPIENT, EFFICIENT_SOLUTION, 0))); + curtaGolf.submit(1, EFFICIENT_SOLUTION, RECIPIENT, 0); } // ------------------------------------------------------------------------- // `run` diff --git a/src/CurtaGolf.sol b/src/CurtaGolf.sol index 5a65000..ef59775 100644 --- a/src/CurtaGolf.sol +++ b/src/CurtaGolf.sol @@ -114,14 +114,6 @@ contract CurtaGolf is ICurtaGolf, KingERC721, Owned { return _submit(_courseId, _solution, _recipient); } - /// @inheritdoc ICurtaGolf - function submitDirectly(uint32 _courseId, bytes memory _solution, address _recipient) - external - returns (uint32) - { - return _submit(_courseId, _solution, _recipient); - } - // ------------------------------------------------------------------------- // `owner`-only functions // ------------------------------------------------------------------------- diff --git a/src/interfaces/ICurtaGolf.sol b/src/interfaces/ICurtaGolf.sol index 1389842..f9b454f 100644 --- a/src/interfaces/ICurtaGolf.sol +++ b/src/interfaces/ICurtaGolf.sol @@ -193,15 +193,4 @@ interface ICurtaGolf { function submit(uint32 _courseId, bytes memory _solution, address _recipient, uint256 _salt) external returns (uint32); - - /// @notice Submits a solution to a course directly, skipping the 2-step - /// commit-reveal process. Only call this function if front-running is not - /// a concern (e.g. the solution is not to become the leading solution). - /// @param _courseId The ID of the course. - /// @param _solution The bytecode of the solution. - /// @param _recipient The address of the recipient. - /// @return The gas used by the solution. - function submitDirectly(uint32 _courseId, bytes memory _solution, address _recipient) - external - returns (uint32); } diff --git a/test/CurtaGolf.t.sol b/test/CurtaGolf.t.sol index fe2ff18..5b820c4 100644 --- a/test/CurtaGolf.t.sol +++ b/test/CurtaGolf.t.sol @@ -284,135 +284,6 @@ contract CurtaGolfTest is BaseTest { } } - // ------------------------------------------------------------------------- - // `submitDirectly` - // ------------------------------------------------------------------------- - - /// @notice Test the emitted events and storage updates upon submitting - /// solutions in the following order: - /// 1. `solver1` submits an inefficient solution but becomes the king. - /// 2. `solver2` submits an efficient solution and becomes the new king. - /// 3. `solver3` submits an inefficient solution and doesn't become the - /// new king. - /// All solvers get `par` NFTs minted to them, but only `solver1` and - /// `solver3` hold ownership of a King NFT. - function test_submitDirectly() public { - // Check that there is no King for course 1. - { - (, uint32 gasUsed, uint32 solutionCount, uint32 kingCount) = curtaGolf.getCourse(1); - assertEq(gasUsed, 0); - assertEq(solutionCount, 0); - assertEq(kingCount, 0); - vm.expectRevert("NOT_MINTED"); - curtaGolf.ownerOf(1); - } - // Check that all solvers have 0 King NFTs. - { - assertEq(curtaGolf.balanceOf(solver1), 0); - assertEq(curtaGolf.balanceOf(solver2), 0); - assertEq(curtaGolf.balanceOf(solver3), 0); - } - // Check that all solvers have 0 Par NFTs. - { - assertEq(par.balanceOf(solver1), 0); - assertEq(par.balanceOf(solver2), 0); - assertEq(par.balanceOf(solver3), 0); - } - - // Submit the inefficient solution as `solver1`. - vm.prank(solver1); - vm.expectEmit(true, true, true, true); - emit Transfer(address(0), solver1, 1); - vm.expectEmit(true, true, false, false); - emit UpdateKing(1, solver1, 0); - vm.expectEmit(true, true, true, true); - emit Transfer(address(0), solver1, (1 << 160) | uint256(uint160(solver1))); - vm.expectEmit(true, true, false, false); - emit SubmitSolution(1, solver1, address(0), 0); - curtaGolf.submitDirectly(1, INEFFICIENT_SOLUTION, solver1); - - // Check that there is 1 King and 1 solution for course 1. - { - (,, uint32 solutionCount, uint32 kingCount) = curtaGolf.getCourse(1); - assertEq(solutionCount, 1); - assertEq(kingCount, 1); - assertEq(curtaGolf.ownerOf(1), solver1); - } - // Check that `solver1` has 1 King NFT, and the others have 0. - { - assertEq(curtaGolf.balanceOf(solver1), 1); - assertEq(curtaGolf.balanceOf(solver2), 0); - assertEq(curtaGolf.balanceOf(solver3), 0); - } - // Check that `solver1` has 1 Par NFT, and the others have 0. - { - assertEq(par.balanceOf(solver1), 1); - assertEq(par.balanceOf(solver2), 0); - assertEq(par.balanceOf(solver3), 0); - } - - // Submit the efficient solution as `solver2`. - vm.prank(solver2); - vm.expectEmit(true, true, true, true); - emit Transfer(solver1, solver2, 1); - vm.expectEmit(true, true, false, false); - emit UpdateKing(1, solver2, 0); - vm.expectEmit(true, true, true, true); - emit Transfer(address(0), solver2, (1 << 160) | uint256(uint160(solver2))); - vm.expectEmit(true, true, false, false); - emit SubmitSolution(1, solver2, address(0), 0); - curtaGolf.submitDirectly(1, EFFICIENT_SOLUTION, solver2); - - // Check that there is 2 Kings and 2 solutions for course 1. - { - (,, uint32 solutionCount, uint32 kingCount) = curtaGolf.getCourse(1); - assertEq(solutionCount, 2); - assertEq(kingCount, 2); - assertEq(curtaGolf.ownerOf(1), solver2); - } - // Check that `solver2` has 1 King NFT, and the others have 0. - { - assertEq(curtaGolf.balanceOf(solver1), 0); - assertEq(curtaGolf.balanceOf(solver2), 1); - assertEq(curtaGolf.balanceOf(solver3), 0); - } - // Check that `solver1` and `solver2` have 1 Par NFT each, and `solver3` - // has 0. - { - assertEq(par.balanceOf(solver1), 1); - assertEq(par.balanceOf(solver2), 1); - assertEq(par.balanceOf(solver3), 0); - } - - // Submit the efficient solution as `solver3`. - vm.prank(solver3); - vm.expectEmit(true, true, true, true); - emit Transfer(address(0), solver3, (1 << 160) | uint256(uint160(solver3))); - vm.expectEmit(true, true, false, false); - emit SubmitSolution(1, solver3, address(0), 0); - curtaGolf.submitDirectly(1, INEFFICIENT_SOLUTION, solver3); - - // Check that there is 2 Kings and 3 solutions for course 1. - { - (,, uint32 solutionCount, uint32 kingCount) = curtaGolf.getCourse(1); - assertEq(solutionCount, 3); - assertEq(kingCount, 2); - assertEq(curtaGolf.ownerOf(1), solver2); - } - // Check that `solver2` has 1 King NFT, and the others have 0. - { - assertEq(curtaGolf.balanceOf(solver1), 0); - assertEq(curtaGolf.balanceOf(solver2), 1); - assertEq(curtaGolf.balanceOf(solver3), 0); - } - // Check each solver has 1 Par NFT each. - { - assertEq(par.balanceOf(solver1), 1); - assertEq(par.balanceOf(solver2), 1); - assertEq(par.balanceOf(solver3), 1); - } - } - // ------------------------------------------------------------------------- // `addCourse` // ------------------------------------------------------------------------- @@ -547,7 +418,10 @@ contract CurtaGolfTest is BaseTest { /// @notice Test that calling `tokenURI` on a minted token succeeds. function test_tokenURI_MintedToken_Succeeds() public { - curtaGolf.submitDirectly(1, EFFICIENT_SOLUTION, solver1); + curtaGolf.commit(keccak256(abi.encode(solver1, EFFICIENT_SOLUTION, 0))); + vm.warp(MIN_COMMIT_AGE + 1); + vm.prank(solver1); + curtaGolf.submit(1, EFFICIENT_SOLUTION, solver1, 0); curtaGolf.tokenURI(1); } }