Skip to content

Commit

Permalink
Update signContext function and fix testValidateMultipleSignedContext…
Browse files Browse the repository at this point in the history
…s test
  • Loading branch information
ninokeldishvili committed Aug 8, 2024
1 parent 8a34441 commit 687321c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions test/concrete/flowErc1155/FlowSignedContextTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ contract FlowSignedContextTest is FlowUtilsAbstractTest, FlowERC1155Test {

SignedContextV1[] memory signedContexts = new SignedContextV1[](2);

signedContexts[0] = vm.signContext(aliceKey, context0);
signedContexts[1] = vm.signContext(aliceKey, context1);
signedContexts[0] = vm.signContext(aliceKey, aliceKey, context0);
signedContexts[1] = vm.signContext(aliceKey, aliceKey, context1);

uint256[] memory stack = generateFlowERC1155Stack(
new ERC1155Transfer[](0),
Expand All @@ -51,8 +51,8 @@ contract FlowSignedContextTest is FlowUtilsAbstractTest, FlowERC1155Test {

// With bad signature in second signed context
SignedContextV1[] memory signedContexts1 = new SignedContextV1[](2);
signedContexts[0] = vm.signContext(aliceKey, context0);
signedContexts[1] = vm.signContext(bobKey, context1);
signedContexts1[0] = vm.signContext(aliceKey, aliceKey, context0);
signedContexts1[1] = vm.signContext(aliceKey, bobKey, context1);

uint256[] memory stack1 = generateFlowERC1155Stack(
new ERC1155Transfer[](0),
Expand All @@ -63,7 +63,7 @@ contract FlowSignedContextTest is FlowUtilsAbstractTest, FlowERC1155Test {
);
interpreterEval2MockCall(stack1, new uint256[](0));

vm.expectRevert(abi.encodeWithSelector(InvalidSignature.selector, 0));
vm.expectRevert(abi.encodeWithSelector(InvalidSignature.selector, 1));
erc1155Flow.flow(evaluable, new uint256[](0), signedContexts1);
}
}
6 changes: 3 additions & 3 deletions test/lib/SignContextLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import {ECDSAUpgradeable as ECDSA} from "openzeppelin/utils/cryptography/ECDSAUp
import {SignedContextV1} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol";

library SignContextLib {
function signContext(Vm vm, uint256 privateKey, uint256[] memory context)
function signContext(Vm vm, uint256 signerPrivateKey, uint256 signaturePrivateKey, uint256[] memory context)
internal
pure
returns (SignedContextV1 memory)
{
SignedContextV1 memory signedContext;

// Store the signer's address in the struct
signedContext.signer = vm.addr(privateKey);
signedContext.signer = vm.addr(signerPrivateKey);
signedContext.context = context; // copy the context data into the struct

// Create a digest of the context data
bytes32 contextHash = keccak256(abi.encodePacked(context));
bytes32 digest = ECDSA.toEthSignedMessageHash(contextHash);

// Create the signature using the cheatCode 'sign'
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(signaturePrivateKey, digest);
signedContext.signature = abi.encodePacked(r, s, v);

return signedContext;
Expand Down

0 comments on commit 687321c

Please sign in to comment.