Skip to content

Commit

Permalink
fix: verify state transition for tap collector thawing signers (TRST-…
Browse files Browse the repository at this point in the history
…R03)

Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone committed Dec 3, 2024
1 parent 670fba7 commit 2bf4456
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/horizon/contracts/interfaces/ITAPCollector.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ interface ITAPCollector is IPaymentsCollector {
*/
error TAPCollectorAuthorizationAlreadyRevoked(address payer, address signer);

/**
* Thrown when attempting to thaw a signer that is already thawing
* @param signer The address of the signer
* @param thawEndTimestamp The timestamp at which the thawing period ends
*/
error TAPCollectorSignerAlreadyThawing(address signer, uint256 thawEndTimestamp);

/**
* Thrown when the signer is not thawing
* @param signer The address of the signer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {

require(authorization.payer == msg.sender, TAPCollectorSignerNotAuthorizedByPayer(msg.sender, signer));
require(!authorization.revoked, TAPCollectorAuthorizationAlreadyRevoked(msg.sender, signer));
require(
authorization.thawEndTimestamp == 0,
TAPCollectorSignerAlreadyThawing(signer, authorization.thawEndTimestamp)
);

authorization.thawEndTimestamp = block.timestamp + REVOKE_SIGNER_THAWING_PERIOD;
emit SignerThawing(msg.sender, signer, authorization.thawEndTimestamp);
Expand Down Expand Up @@ -174,10 +178,7 @@ contract TAPCollector is EIP712, GraphDirectory, ITAPCollector {

// Ensure RAV payer matches the authorized payer
address payer = authorizedSigners[signer].payer;
require(
signedRAV.rav.payer == payer,
TAPCollectorInvalidRAVPayer(payer, signedRAV.rav.payer)
);
require(signedRAV.rav.payer == payer, TAPCollectorInvalidRAVPayer(payer, signedRAV.rav.payer));

address dataService = signedRAV.rav.dataService;
address receiver = signedRAV.rav.serviceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,17 @@ contract TAPCollectorThawSignerTest is TAPCollectorTest {
vm.expectRevert(expectedError);
tapCollector.thawSigner(signer);
}

function testTAPCollector_ThawSigner_RevertWhen_AlreadyThawing() public useGateway useSigner {
_thawSigner(signer);

(,uint256 thawEndTimestamp,) = tapCollector.authorizedSigners(signer);
bytes memory expectedError = abi.encodeWithSelector(
ITAPCollector.TAPCollectorSignerAlreadyThawing.selector,
signer,
thawEndTimestamp
);
vm.expectRevert(expectedError);
tapCollector.thawSigner(signer);
}
}

0 comments on commit 2bf4456

Please sign in to comment.