-
Notifications
You must be signed in to change notification settings - Fork 158
[audit-01] fix: [TRST-H-1] IndexingAgreement.collect() on CanceledByPayer #1198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matiasedgeandnode
wants to merge
2
commits into
ma/indexing-payments-audited
Choose a base branch
from
ma/indexing-payments-audit-fixes-01-H-1
base: ma/indexing-payments-audited
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/horizon/test/unit/data-service/utilities/ProvisionManager.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.27; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { ProvisionManager } from "../../../../contracts/data-service/utilities/ProvisionManager.sol"; | ||
import { IHorizonStakingTypes } from "../../../../contracts/interfaces/internal/IHorizonStakingTypes.sol"; | ||
import { PartialControllerMock } from "../../mocks/PartialControllerMock.t.sol"; | ||
import { HorizonStakingMock } from "../../mocks/HorizonStakingMock.t.sol"; | ||
import { ProvisionManagerImpl } from "./ProvisionManagerImpl.t.sol"; | ||
|
||
contract ProvisionManagerTest is Test { | ||
ProvisionManagerImpl internal _provisionManager; | ||
HorizonStakingMock internal _horizonStakingMock; | ||
|
||
function setUp() public { | ||
_horizonStakingMock = new HorizonStakingMock(); | ||
|
||
PartialControllerMock.Entry[] memory entries = new PartialControllerMock.Entry[](1); | ||
entries[0] = PartialControllerMock.Entry({ name: "Staking", addr: address(_horizonStakingMock) }); | ||
_provisionManager = new ProvisionManagerImpl(address(new PartialControllerMock(entries))); | ||
} | ||
|
||
/* solhint-disable graph/func-name-mixedcase */ | ||
|
||
function test_OnlyValidProvision(address serviceProvider) public { | ||
vm.expectRevert( | ||
abi.encodeWithSelector(ProvisionManager.ProvisionManagerProvisionNotFound.selector, serviceProvider) | ||
); | ||
_provisionManager.onlyValidProvision_(serviceProvider); | ||
|
||
IHorizonStakingTypes.Provision memory provision; | ||
provision.createdAt = 1; | ||
|
||
_horizonStakingMock.setProvision(serviceProvider, address(_provisionManager), provision); | ||
|
||
_provisionManager.onlyValidProvision_(serviceProvider); | ||
} | ||
|
||
function test_OnlyAuthorizedForProvision(address serviceProvider, address sender) public { | ||
vm.expectRevert( | ||
abi.encodeWithSelector(ProvisionManager.ProvisionManagerNotAuthorized.selector, serviceProvider, sender) | ||
); | ||
vm.prank(sender); | ||
_provisionManager.onlyAuthorizedForProvision_(serviceProvider); | ||
|
||
_horizonStakingMock.setIsAuthorized(serviceProvider, address(_provisionManager), sender, true); | ||
vm.prank(sender); | ||
_provisionManager.onlyAuthorizedForProvision_(serviceProvider); | ||
} | ||
|
||
/* solhint-enable graph/func-name-mixedcase */ | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/horizon/test/unit/data-service/utilities/ProvisionManagerImpl.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.27; | ||
|
||
import { ProvisionManager } from "../../../../contracts/data-service/utilities/ProvisionManager.sol"; | ||
import { GraphDirectory } from "../../../../contracts/utilities/GraphDirectory.sol"; | ||
|
||
contract ProvisionManagerImpl is GraphDirectory, ProvisionManager { | ||
constructor(address controller) GraphDirectory(controller) {} | ||
|
||
function onlyValidProvision_(address serviceProvider) public view onlyValidProvision(serviceProvider) {} | ||
|
||
function onlyAuthorizedForProvision_( | ||
address serviceProvider | ||
) public view onlyAuthorizedForProvision(serviceProvider) {} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.27; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { StakeClaims } from "../../../contracts/data-service/libraries/StakeClaims.sol"; | ||
|
||
contract StakeClaimsTest is Test { | ||
/* solhint-disable graph/func-name-mixedcase */ | ||
|
||
function test_BuildStakeClaimId(address dataService, address serviceProvider, uint256 nonce) public pure { | ||
bytes32 id = StakeClaims.buildStakeClaimId(dataService, serviceProvider, nonce); | ||
bytes32 expectedId = keccak256(abi.encodePacked(dataService, serviceProvider, nonce)); | ||
assertEq(id, expectedId, "StakeClaim ID does not match expected value"); | ||
} | ||
|
||
/* solhint-enable graph/func-name-mixedcase */ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.27; | ||
|
||
import { IHorizonStakingTypes } from "../../../contracts/interfaces/internal/IHorizonStakingTypes.sol"; | ||
|
||
contract HorizonStakingMock { | ||
mapping(address => mapping(address => IHorizonStakingTypes.Provision)) public provisions; | ||
mapping(address => mapping(address => mapping(address => bool))) public authorizations; | ||
|
||
function setProvision( | ||
address serviceProvider, | ||
address verifier, | ||
IHorizonStakingTypes.Provision memory provision | ||
) external { | ||
provisions[serviceProvider][verifier] = provision; | ||
} | ||
|
||
function getProvision( | ||
address serviceProvider, | ||
address verifier | ||
) external view returns (IHorizonStakingTypes.Provision memory) { | ||
return provisions[serviceProvider][verifier]; | ||
} | ||
|
||
function isAuthorized(address serviceProvider, address verifier, address operator) external view returns (bool) { | ||
return authorizations[serviceProvider][verifier][operator]; | ||
} | ||
|
||
function setIsAuthorized(address serviceProvider, address verifier, address operator, bool authorized) external { | ||
authorizations[serviceProvider][verifier][operator] = authorized; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.27; | ||
|
||
import { PartialControllerMock } from "./PartialControllerMock.t.sol"; | ||
|
||
contract InvalidControllerMock is PartialControllerMock { | ||
constructor() PartialControllerMock(new PartialControllerMock.Entry[](0)) {} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/horizon/test/unit/mocks/PartialControllerMock.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.27; | ||
|
||
import { Test } from "forge-std/Test.sol"; | ||
|
||
import { ControllerMock } from "../../../contracts/mocks/ControllerMock.sol"; | ||
|
||
contract PartialControllerMock is ControllerMock, Test { | ||
struct Entry { | ||
string name; | ||
address addr; | ||
} | ||
|
||
address private _invalidContractAddress; | ||
|
||
Entry[] private _contracts; | ||
|
||
constructor(Entry[] memory contracts) ControllerMock(address(0)) { | ||
for (uint256 i = 0; i < contracts.length; i++) { | ||
_contracts.push(Entry({ name: contracts[i].name, addr: contracts[i].addr })); | ||
} | ||
_invalidContractAddress = makeAddr("invalidContractAddress"); | ||
} | ||
|
||
function getContractProxy(bytes32 data) external view override returns (address) { | ||
for (uint256 i = 0; i < _contracts.length; i++) { | ||
if (keccak256(abi.encodePacked(_contracts[i].name)) == data) { | ||
return _contracts[i].addr; | ||
} | ||
} | ||
return _invalidContractAddress; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
...ges/horizon/test/unit/payments/recurring-collector/RecurringCollectorControllerMock.t.sol
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
packages/horizon/test/unit/payments/recurring-collector/base.t.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.27; | ||
|
||
import { IRecurringCollector } from "../../../../contracts/interfaces/IRecurringCollector.sol"; | ||
|
||
import { RecurringCollectorSharedTest } from "./shared.t.sol"; | ||
|
||
contract RecurringCollectorBaseTest is RecurringCollectorSharedTest { | ||
/* | ||
* TESTS | ||
*/ | ||
|
||
/* solhint-disable graph/func-name-mixedcase */ | ||
|
||
function test_RecoverRCASigner(FuzzyTestAccept memory fuzzyTestAccept) public view { | ||
uint256 signerKey = boundKey(fuzzyTestAccept.unboundedSignerKey); | ||
IRecurringCollector.SignedRCA memory signedRCA = _recurringCollectorHelper.generateSignedRCA( | ||
fuzzyTestAccept.rca, | ||
signerKey | ||
); | ||
|
||
assertEq( | ||
_recurringCollector.recoverRCASigner(signedRCA), | ||
vm.addr(signerKey), | ||
"Recovered RCA signer does not match" | ||
); | ||
} | ||
|
||
function test_RecoverRCAUSigner(FuzzyTestUpdate memory fuzzyTestUpdate) public view { | ||
uint256 signerKey = boundKey(fuzzyTestUpdate.fuzzyTestAccept.unboundedSignerKey); | ||
IRecurringCollector.SignedRCAU memory signedRCAU = _recurringCollectorHelper.generateSignedRCAU( | ||
fuzzyTestUpdate.rcau, | ||
signerKey | ||
); | ||
|
||
assertEq( | ||
_recurringCollector.recoverRCAUSigner(signedRCAU), | ||
vm.addr(signerKey), | ||
"Recovered RCAU signer does not match" | ||
); | ||
} | ||
|
||
/* solhint-enable graph/func-name-mixedcase */ | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.