Skip to content

Commit

Permalink
test: hello world signing key
Browse files Browse the repository at this point in the history
  • Loading branch information
stevennevins committed Oct 1, 2024
1 parent 1ad8c96 commit 367d8c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
17 changes: 5 additions & 12 deletions contracts/src/HelloWorldServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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;
Expand Down
23 changes: 18 additions & 5 deletions contracts/test/HelloWorldServiceManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 367d8c4

Please sign in to comment.