Skip to content

Commit

Permalink
Scope transfer frontrunning fix (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
robdoesstuff committed Aug 29, 2023
1 parent cc618b6 commit a9217a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/PatchworkProtocol.sol
Expand Up @@ -46,6 +46,7 @@ contract PatchworkProtocol {
function transferScopeOwnership(string calldata scopeName, address newOwner) public {
Scope storage s = _scopes[scopeName];
require(msg.sender == s.owner, "not authorized");
require(newOwner != address(0), "not allowed");
s.owner = newOwner;
}

Expand Down
10 changes: 10 additions & 0 deletions test/PatchworkProtocol.t.sol
Expand Up @@ -220,6 +220,16 @@ contract PatchworkProtocolTest is Test {
prot.batchAssignNFT(fragmentAddresses, fragments, address(testPatchLiteRefNFT), fragmentTokenId2);
}

function testScopeTransferCannotBeFrontrun() public {
address maliciousActor = address(120938);
// A malicious actor attempts to preconfigure and transfer a scope to 0 so an unsuspecting actor claims it but it already has operators preconfigured
vm.startPrank(maliciousActor);
prot.claimScope("foo");
prot.addOperator("foo", address(4));
vm.expectRevert("not allowed");
prot.transferScopeOwnership("foo", address(0));
}

function testUserAssignNFT() public {
uint256 testBaseNFTTokenId = testBaseNFT.mint(userAddress);

Expand Down

0 comments on commit a9217a2

Please sign in to comment.