Skip to content
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

feat: add access control for authorized callers #62

Merged
merged 13 commits into from
Sep 25, 2024

Conversation

xorsal
Copy link
Contributor

@xorsal xorsal commented Sep 19, 2024

🤖 Linear

Closes OPO-646

@gas1cent gas1cent requested review from 0xJabberwock, 0xShaito and gas1cent and removed request for 0xJabberwock and 0xShaito September 19, 2024 15:03
solidity/test/integration/IntegrationBase.sol Outdated Show resolved Hide resolved
Comment on lines +128 to +130
address[] memory authorizedCallers = new address[](1);
authorizedCallers[0] = address(bondEscalationModule);
bondEscalationAccounting = new BondEscalationAccounting(oracle, authorizedCallers);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note here that we don't have any integration tests for the BondEscalationResolutionModule, only for the dispute one. Hence we're not adding it to the list of authorized callers.

Comment on lines 223 to 226
vm.startPrank(unauthorizedCaller);
// Check: does it revert if the caller is not authorized?
vm.expectRevert(IBondEscalationAccounting.BondEscalationAccounting_UnauthorizedCaller.selector);

vm.prank(unauthorizedCaller);
Copy link
Contributor Author

@xorsal xorsal Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed vm.prank to vm.startPrank here because I was testing something but it doesn't hurt tbh

vm.expectRevert(ValidatorLib.ValidatorLib_InvalidDisputeBody.selector);
vm.expectRevert(IBondEscalationAccounting.BondEscalationAccounting_UnauthorizedCaller.selector);
Copy link
Member

@0xJabberwock 0xJabberwock Sep 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the erased expectation of reversion should still be tested, since the attacker could theoretically be an authorized caller.

Copy link
Contributor Author

@xorsal xorsal Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.
What do you think about mocking authorizedCallers immediately after the line you selected, something like this:

stdstore
  .target(address(_bondEscalationAccounting))
  .sig('authorizedCallers(address)')
  .with_key(_attacker)
  .checked_write(true);

vm.expectRevert(ValidatorLib.ValidatorLib_InvalidDisputeBody.selector);
_bondEscalationAccounting.releasePledge(mockRequest, mockDispute, _attacker, usdc, _pledgeSize * 4);

Copy link
Member

@0xJabberwock 0xJabberwock Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That could work, although I'd try to avoid mocking in integration tests—a workaround could be to redeploy BondEscalationAccounting with the attacker as an authorized caller (maybe in a separate test case).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect 👌
Yes, I thought about that but redeploying the BondEscalationAccounting is somewhat cumbersome because integration tests rely on common variables like mockRequest.

solidity/test/integration/BondEscalation.t.sol Outdated Show resolved Hide resolved
Comment on lines 460 to 457
////////////////// DISPUTE ESCALATION ////////////////////////
// Step 1: Proposer pledges against the dispute
_deposit(_bondEscalationAccounting, proposer, usdc, _pledgeSize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the whole dispute escalation flow should be replicated in test_authorizedAttackerAllowedModules, as these tests are meant to simulate a specific attack which was once possible.

Copy link
Contributor Author

@xorsal xorsal Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this further escalation is only meant to exemplify a particular scenario (a request/dispute gathers tokens from multiple parties/sources) so it won't change the final result (revert when the attacker tries to finalize the attack) but I can add it to replicate the exact same scenario of attackerAllowedModules if that makes it clearer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the purpose of these test cases in particular should be to be anti-regressive with a specific bug, hence why I wouldn't disesteem the featured scenario in any of them. However, we can invoke its creator's opinion: @0xShaito.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I agree with your reasoning. I'll revert that commit and redo it.

solidity/test/integration/BondEscalation.t.sol Outdated Show resolved Hide resolved
@xorsal xorsal force-pushed the feat/BEA-authorized-callers branch from 0aac1a0 to c149038 Compare September 25, 2024 01:41
Copy link

linear bot commented Sep 25, 2024

@gas1cent gas1cent merged commit 7dd25d3 into dev Sep 25, 2024
3 checks passed
@gas1cent gas1cent deleted the feat/BEA-authorized-callers branch September 25, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants