From 367d8c4ccc3317f65f8ece7a6b4f13081a968d23 Mon Sep 17 00:00:00 2001 From: steven Date: Tue, 1 Oct 2024 17:19:13 -0400 Subject: [PATCH] test: hello world signing key --- contracts/src/HelloWorldServiceManager.sol | 17 ++++---------- contracts/test/HelloWorldServiceManager.t.sol | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/contracts/src/HelloWorldServiceManager.sol b/contracts/src/HelloWorldServiceManager.sol index 28e75221..145e0a5e 100644 --- a/contracts/src/HelloWorldServiceManager.sol +++ b/contracts/src/HelloWorldServiceManager.sol @@ -71,14 +71,8 @@ contract HelloWorldServiceManager is ECDSAServiceManagerBase, IHelloWorldService function respondToTask( Task calldata task, uint32 referenceTaskIndex, - bytes calldata signature + bytes memory signature ) external { - bytes32 taskDigest; - bytes4 magicValue = IERC1271Upgradeable.isValidSignature.selector; - if (!(magicValue == ECDSAStakeRegistry(stakeRegistry).isValidSignature(taskDigest,signature))){ - revert(); - } - // check that the task is valid, hasn't been responsed yet, and is being responded in time require( keccak256(abi.encode(task)) == allTaskHashes[referenceTaskIndex], @@ -92,11 +86,10 @@ contract HelloWorldServiceManager is ECDSAServiceManagerBase, IHelloWorldService // The message that was signed bytes32 messageHash = keccak256(abi.encodePacked("Hello, ", task.name)); bytes32 ethSignedMessageHash = messageHash.toEthSignedMessageHash(); - - // Recover the signer address from the signature - address signer = ethSignedMessageHash.recover(signature); - - require(signer == msg.sender, "Message signer is not operator"); + bytes4 magicValue = IERC1271Upgradeable.isValidSignature.selector; + if (!(magicValue == ECDSAStakeRegistry(stakeRegistry).isValidSignature(ethSignedMessageHash,signature))){ + revert(); + } // updating the storage with task responses allTaskResponses[msg.sender][referenceTaskIndex] = signature; diff --git a/contracts/test/HelloWorldServiceManager.t.sol b/contracts/test/HelloWorldServiceManager.t.sol index 55034e95..f7ad8b55 100644 --- a/contracts/test/HelloWorldServiceManager.t.sol +++ b/contracts/test/HelloWorldServiceManager.t.sol @@ -259,9 +259,15 @@ contract HelloWorldTaskManagerSetup is Test { bytes memory signature = signWithSigningKey(operator, messageHash); - vm.prank(operator.key.addr); + address[] memory operators = new address[](1); + operators[0]=operator.key.addr; + bytes[] memory signatures = new bytes[](1); + signatures[0]= signature; + + bytes memory signedTask = abi.encode(operators, signatures, uint32(block.number)); + IHelloWorldServiceManager(helloWorldDeployment.helloWorldServiceManager).respondToTask( - task, referenceTaskIndex, signature + task, referenceTaskIndex, signedTask ); } } @@ -415,9 +421,16 @@ contract RespondToTask is HelloWorldTaskManagerSetup { bytes32 messageHash = keccak256(abi.encodePacked("Hello, ", taskName)); bytes32 ethSignedMessageHash = messageHash.toEthSignedMessageHash(); - bytes memory signature = signWithOperatorKey(operators[0], ethSignedMessageHash); // TODO: Use signing key after changes to service manager + bytes memory signature = signWithSigningKey(operators[0], ethSignedMessageHash); // TODO: Use signing key after changes to service manager + + address[] memory operatorsMem = new address[](1); + operatorsMem[0]=operators[0].key.addr; + bytes[] memory signatures = new bytes[](1); + signatures[0]= signature; + + bytes memory signedTask = abi.encode(operatorsMem, signatures, uint32(block.number)); - vm.prank(operators[0].key.addr); - sm.respondToTask(newTask, taskIndex, signature); + vm.roll(block.number+1); + sm.respondToTask(newTask, taskIndex, signedTask); } }