Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

feat: account guard #514

Closed
wants to merge 10 commits into from
Closed

feat: account guard #514

wants to merge 10 commits into from

Conversation

0xrajath
Copy link
Contributor

@0xrajath 0xrajath commented Apr 2, 2024

Motivation:

We need to protect the execute function on the LlamaAccount contract so that it can safely make external calls.

Modifications:

  • ILlamaActionGuardMinimalProxy interface that inherits ILlamaActionGuard
  • A generic LlamaActionGuardFactory that can deploy any action guard.
  • LlamaAccountExecuteGuard that protects the execute function on the LlamaAccount contract
  • Updated DeployLlamaFactory script to include new contracts

Result:

The execute function on Llama accounts can be used safely

@0xrajath 0xrajath self-assigned this Apr 2, 2024
@0xrajath 0xrajath requested a review from AustinGreen as a code owner April 2, 2024 01:40
Comment on lines +56 to +57
/// @notice A mapping of authorized targets and their call type.
mapping(address target => mapping(bool withDelegatecall => bool isAuthorized)) public authorizedTargets;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion but do you think we should add selector allowlisting in this guard too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me think about it for a bit.

Copy link
Contributor Author

@0xrajath 0xrajath Apr 3, 2024

Choose a reason for hiding this comment

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

After thinking about it for a bit. I think it makes sense to add selector allowlisting in this guard too. But we can rework the mapping to not make it so deep.

We would have two mappings:

/// @notice A mapping of authorized selectors that can be called within a target.
mapping(address target => mapping(bytes4 selector => bool isAuthorized)) public authorizedSelectors;

/// @notice A mapping of targets and their call type.
mapping(address target => bool withDelegatecall) public targetCallType;

Comment on lines +95 to +99
/// @inheritdoc ILlamaActionGuard
function validatePreActionExecution(ActionInfo calldata actionInfo) external pure {}

/// @inheritdoc ILlamaActionGuard
function validatePostActionExecution(ActionInfo calldata actionInfo) external pure {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return true for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interfaces don't have a return value.

address llamaExecutor; // The address of the Llama executor.
ILlamaActionGuardMinimalProxy actionGuardLogic; // The logic contract of the new action guard.
bytes initializationData; // The initialization data for the new action guard.
uint256 nonce; // The nonce of the new action guard.
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea for the nonce is instances will want to deploy multiple guards with the same initialization data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the salt is (msg.sender, actionGuardConfig.llamaExecutor, actionGuardConfig.nonce). So the nonce will allow the same msg.sender to deploy multiple guards for the same executor (When it's deployed through an action, the msg.sender and executor will be the same, but this gives us the optionality to deploy on behalf of an instance as well).

Initialization data is not used in the salt since that data can be altered through setters in the guard later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively I could use something like name instead of a nonce. Just wanted something to differentiate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added name in b4412bb

Copy link
Contributor Author

@0xrajath 0xrajath Apr 3, 2024

Choose a reason for hiding this comment

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

And kept nonce as well as an optionality to allow multiple deployments if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just edit ILlamaActionGuard? It's not used anywhere besides tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in the LlamaCore which is why I didn't want to touch it.

Copy link

github-actions bot commented Apr 3, 2024

Coverage after merging rajath/account-guard into main will be

86.87%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   LlamaCore.sol99.31%97.44%100%100%299, 399
   LlamaExecutor.sol80%50%100%100%33
   LlamaFactory.sol100%100%100%100%
   LlamaLens.sol72.09%20%100%82.61%174–175, 178, 178, 178–179, 179, 179–180, 180, 180, 188
   LlamaPolicy.sol91.53%88.89%94.59%91.38%353, 392, 392, 392–394, 394, 394, 396–399, 401, 419
   LlamaPolicyMetadata.sol100%100%100%100%
src/accounts
   LlamaAccount.sol100%100%100%100%
   LlamaAccountWithDelegation.sol100%100%100%100%
src/guards
   LlamaAccountExecuteGuard.sol0%0%0%0%100, 115–118, 78–82, 92–93, 93, 93, 99, 99, 99
   LlamaActionGuardFactory.sol0%100%0%0%39, 44, 46, 50
src/lib
   ERC721NonTransferableMinimalProxy.sol70.42%72.73%72.73%68.42%102, 104, 106, 118–120, 190, 88, 88, 88, 90, 90, 90, 92, 92, 92, 97, 99
   LlamaUtils.sol100%100%100%100%
   PolicyholderCheckpoints.sol55.88%50%81.82%53.62%130, 184–186, 186, 186–187, 189, 192, 222, 229, 229–231, 233, 233–235, 237, 237–239, 241, 241–243, 262, 265–271, 278, 46, 46–48, 48, 48–49, 51
   SupplyCheckpoints.sol57.14%50%83.33%54.93%131, 183–185, 185, 185–186, 188, 191, 235, 242, 242–244, 246, 246–248, 250, 250–252, 254, 254–256, 275, 278–284, 291, 50, 50–52, 52, 52–53, 55
src/llama-scripts
   LlamaAccountTokenDelegationScript.sol100%100%100%100%
   LlamaGovernanceScript.sol96.24%64.29%100%100%131, 133, 160, 171, 228
   LlamaInstanceConfigBase.sol100%100%100%100%
   LlamaInstanceConfigScriptTemplate.sol100%100%100%100%
src/strategies/absolute
   LlamaAbsolutePeerReview.sol100%100%100%100%
   LlamaAbsoluteQuorum.sol100%100%100%100%
   LlamaAbsoluteStrategyBase.sol94.81%87.50%90.91%98%248, 251, 301
src/strategies/relative
   LlamaRelativeHolderQuorum.sol91.67%75%100%100%52, 59
   LlamaRelativeQuantityQuorum.sol0%0%0%0%28, 28, 28–30, 42, 42, 42–44, 51–52, 52, 52–53, 58–59, 59, 59–60
   LlamaRelativeStrategyBase.sol97.62%90.91%100%100%208, 310
   LlamaRelativeUniqueHolderQuorum.sol93.33%83.33%100%100%54, 61

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants