Skip to content

Commit c899f2d

Browse files
authored
Merge pull request #5 from base/amie/push-authorization-into-policies
Prototype updates
2 parents 6309a70 + 6e8aca4 commit c899f2d

15 files changed

Lines changed: 562 additions & 685 deletions

README.md

Lines changed: 13 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,43 @@
1-
## Foundry
1+
### account-permissions
22

3-
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
3+
A modular system for allowing smart contract users the ability to authorize third parties to take specific, well-defined, onchain actions via their account.
44

5-
Foundry consists of:
5+
### How it works (high level)
66

7-
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8-
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9-
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10-
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
7+
- **`src/PolicyManager.sol`**: installs policy instances authorized by the account and executes policy-prepared calldata on the account.
8+
- **`src/PolicyTypes.sol`**: shared type definitions (notably `PolicyTypes.Install`) used by the manager and policies.
9+
- **`src/policies/`**: example policies (each policy defines its own authorization semantics via `authorize(...)` and constructs wallet calldata via `onExecute(...)`).
1110

12-
## Documentation
11+
### Setup
1312

14-
https://book.getfoundry.sh/
15-
16-
## Usage
17-
18-
### Getting started (submodules)
19-
20-
This repo uses git submodules for Foundry dependencies (in `lib/`).
13+
This repo uses git submodules for dependencies (in `lib/`).
2114

2215
Clone with submodules:
2316

2417
```shell
25-
$ git clone --recurse-submodules <repo>
18+
git clone --recurse-submodules <repo>
2619
```
2720

2821
If you already cloned without submodules:
2922

3023
```shell
31-
$ git submodule update --init --recursive
32-
```
33-
34-
Then build / test as usual:
35-
36-
```shell
37-
$ forge build
38-
$ forge test
39-
```
40-
41-
To update dependencies later:
42-
43-
```shell
44-
$ forge install
45-
$ git submodule update --init --recursive
24+
git submodule update --init --recursive
4625
```
4726

4827
### Build
4928

5029
```shell
51-
$ forge build
30+
forge build
5231
```
5332

5433
### Test
5534

5635
```shell
57-
$ forge test
36+
forge test --offline
5837
```
5938

6039
### Format
6140

6241
```shell
63-
$ forge fmt
64-
```
65-
66-
### Gas Snapshots
67-
68-
```shell
69-
$ forge snapshot
70-
```
71-
72-
### Anvil
73-
74-
```shell
75-
$ anvil
76-
```
77-
78-
### Deploy
79-
80-
```shell
81-
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
82-
```
83-
84-
### Cast
85-
86-
```shell
87-
$ cast <subcommand>
88-
```
89-
90-
### Help
91-
92-
```shell
93-
$ forge --help
94-
$ anvil --help
95-
$ cast --help
42+
forge fmt
9643
```
Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import {ReentrancyGuard} from "openzeppelin-contracts/contracts/utils/Reentrancy
55
import {EIP712} from "solady/utils/EIP712.sol";
66

77
import {PublicERC6492Validator} from "./PublicERC6492Validator.sol";
8-
import {PermissionTypes} from "./PermissionTypes.sol";
8+
import {PolicyTypes} from "./PolicyTypes.sol";
99
import {Policy} from "./policies/Policy.sol";
1010

11-
/// @title PermissionManager
11+
/// @title PolicyManager
1212
/// @notice Wallet-agnostic module that installs policies authorized by the account and executes policy-prepared
13-
/// calldata on the account using an authority signature or direct call.
14-
contract PermissionManager is EIP712, ReentrancyGuard {
13+
/// calldata on the account.
14+
contract PolicyManager is EIP712, ReentrancyGuard {
1515
/// @notice Separated contract for validating signatures and executing ERC-6492 side effects.
1616
PublicERC6492Validator public immutable PUBLIC_ERC6492_VALIDATOR;
1717

@@ -72,7 +72,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
7272
/// @notice Install a policy via a signature from the account.
7373
/// @dev Compatible with ERC-6492 signatures including side effects.
7474
function installPolicyWithSignature(
75-
PermissionTypes.Install calldata install,
75+
PolicyTypes.Install calldata install,
7676
bytes calldata policyConfig,
7777
bytes calldata userSig
7878
) external nonReentrant returns (bytes32 policyId) {
@@ -96,7 +96,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
9696
}
9797

9898
/// @notice Install a policy via a direct call from the account.
99-
function installPolicy(PermissionTypes.Install calldata install, bytes calldata policyConfig)
99+
function installPolicy(PolicyTypes.Install calldata install, bytes calldata policyConfig)
100100
external
101101
nonReentrant
102102
requireSender(install.account)
@@ -119,7 +119,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
119119
/// @notice Revoke a policy via a signature from the account.
120120
/// @dev Compatible with ERC-6492 signatures including side effects.
121121
function revokePolicyWithSignature(
122-
PermissionTypes.Install calldata install,
122+
PolicyTypes.Install calldata install,
123123
bytes calldata policyConfig,
124124
bytes calldata userSig
125125
) external nonReentrant returns (bytes32 policyId) {
@@ -143,7 +143,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
143143
}
144144

145145
/// @notice Revoke a policy via a direct call from the account.
146-
function revokePolicy(PermissionTypes.Install calldata install, bytes calldata policyConfig)
146+
function revokePolicy(PolicyTypes.Install calldata install, bytes calldata policyConfig)
147147
external
148148
nonReentrant
149149
requireSender(install.account)
@@ -162,15 +162,15 @@ contract PermissionManager is EIP712, ReentrancyGuard {
162162
emit PolicyRevoked(policyId, install.account, install.policy);
163163
}
164164

165-
/// @notice Execute an action authorized by an authority for an installed policy instance.
166-
/// @dev Policy defines authority semantics and returns wallet-specific calldata for the account.
165+
/// @notice Execute an action for an installed policy instance.
166+
/// @dev Policy defines authorization semantics and returns wallet-specific calldata for the account.
167167
function execute(
168-
PermissionTypes.Install calldata install,
168+
PolicyTypes.Install calldata install,
169169
bytes calldata policyConfig,
170170
bytes calldata policyData,
171171
uint256 execNonce,
172172
uint48 deadline,
173-
bytes calldata authoritySig
173+
bytes calldata authorizationData
174174
) external nonReentrant {
175175
_checkPolicyConfigHash(install.policyConfigHash, policyConfig);
176176
_checkInstallWindow(install.validAfter, install.validUntil);
@@ -179,17 +179,12 @@ contract PermissionManager is EIP712, ReentrancyGuard {
179179
bytes32 policyId = getInstallStructHash(install);
180180
_getActivePolicyState(policyId);
181181

182-
address authority = _policyAuthority(install.policy, policyConfig);
183182
bytes32 execDigest = _getExecutionDigest(policyId, install, keccak256(policyData), execNonce, deadline);
184183

185184
if (_usedExecutionDigest[execDigest]) revert InvalidSignature();
186185
_usedExecutionDigest[execDigest] = true;
187186

188-
if (msg.sender != authority) {
189-
if (!PUBLIC_ERC6492_VALIDATOR.isValidSignatureNowAllowSideEffects(authority, execDigest, authoritySig)) {
190-
revert InvalidSignature();
191-
}
192-
}
187+
Policy(install.policy).authorize(install, execNonce, policyConfig, policyData, execDigest, msg.sender, authorizationData);
193188

194189
(bytes memory accountCallData, bytes memory postCallData) =
195190
_policyOnExecute(install.policy, install, execNonce, policyConfig, policyData);
@@ -199,7 +194,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
199194
emit Executed(policyId, install.account, install.policy, execNonce);
200195
}
201196

202-
function getInstallStructHash(PermissionTypes.Install calldata install) public pure returns (bytes32) {
197+
function getInstallStructHash(PolicyTypes.Install calldata install) public pure returns (bytes32) {
203198
return keccak256(
204199
abi.encode(
205200
INSTALL_TYPEHASH,
@@ -241,7 +236,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
241236

242237
function _getExecutionDigest(
243238
bytes32 policyId,
244-
PermissionTypes.Install calldata install,
239+
PolicyTypes.Install calldata install,
245240
bytes32 policyDataHash,
246241
uint256 nonce,
247242
uint48 deadline
@@ -267,13 +262,9 @@ contract PermissionManager is EIP712, ReentrancyGuard {
267262
if (!success) revert AccountCallFailed(account, returnData);
268263
}
269264

270-
function _policyAuthority(address policy, bytes calldata policyConfig) internal view returns (address) {
271-
return Policy(policy).authority(policyConfig);
272-
}
273-
274265
function _policyOnExecute(
275266
address policy,
276-
PermissionTypes.Install calldata install,
267+
PolicyTypes.Install calldata install,
277268
uint256 execNonce,
278269
bytes calldata policyConfig,
279270
bytes calldata policyData
@@ -290,7 +281,7 @@ contract PermissionManager is EIP712, ReentrancyGuard {
290281
}
291282

292283
function _domainNameAndVersion() internal pure override returns (string memory name, string memory version) {
293-
name = "Permission Manager";
284+
name = "Policy Manager";
294285
version = "1";
295286
}
296287
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.23;
33

4-
/// @notice Shared types for PermissionManager and policies to avoid circular imports.
5-
library PermissionTypes {
4+
/// @notice Shared types for PolicyManager and policies to avoid circular imports.
5+
library PolicyTypes {
66
/// @notice Policy installation parameters authorized by the account.
77
struct Install {
88
address account;
@@ -14,4 +14,3 @@ library PermissionTypes {
1414
}
1515
}
1616

17-

src/policies/CoinbaseSmartWalletSingleCallPolicy.sol

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)