@ensuro/access-managed-proxy 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +47 -4
  2. package/build/build-info.json +1 -1
  3. package/build/contracts/AMPUtils.sol/AMPUtils.json +22 -0
  4. package/build/contracts/AccessManagedProxy.sol/AccessManagedProxy.json +71 -3
  5. package/build/contracts/AccessManagedProxyBase.sol/AccessManagedProxyBase.json +147 -0
  6. package/build/contracts/interfaces/IAccessManagedProxy.sol/IAccessManagedProxy.json +98 -0
  7. package/build/contracts/mock/DummyAccessManaged.sol/DummyAccessManaged.json +321 -0
  8. package/build/contracts/mock/DummyImplementation.sol/DummyImplementation.json +95 -2
  9. package/contracts/AMPUtils.sol +88 -0
  10. package/contracts/AccessManagedProxy.sol +39 -51
  11. package/contracts/AccessManagedProxyBase.sol +74 -0
  12. package/contracts/interfaces/IAccessManagedProxy.sol +51 -0
  13. package/contracts/mock/DummyAccessManaged.sol +56 -0
  14. package/contracts/mock/DummyImplementation.sol +19 -2
  15. package/js/deployProxy.js +69 -0
  16. package/package.json +1 -1
  17. package/build/contracts/amps/AccessManagedProxyS1.sol/AccessManagedProxyS1.json +0 -123
  18. package/build/contracts/amps/AccessManagedProxyS10.sol/AccessManagedProxyS10.json +0 -123
  19. package/build/contracts/amps/AccessManagedProxyS11.sol/AccessManagedProxyS11.json +0 -123
  20. package/build/contracts/amps/AccessManagedProxyS12.sol/AccessManagedProxyS12.json +0 -123
  21. package/build/contracts/amps/AccessManagedProxyS13.sol/AccessManagedProxyS13.json +0 -123
  22. package/build/contracts/amps/AccessManagedProxyS14.sol/AccessManagedProxyS14.json +0 -123
  23. package/build/contracts/amps/AccessManagedProxyS15.sol/AccessManagedProxyS15.json +0 -123
  24. package/build/contracts/amps/AccessManagedProxyS16.sol/AccessManagedProxyS16.json +0 -123
  25. package/build/contracts/amps/AccessManagedProxyS17.sol/AccessManagedProxyS17.json +0 -123
  26. package/build/contracts/amps/AccessManagedProxyS18.sol/AccessManagedProxyS18.json +0 -123
  27. package/build/contracts/amps/AccessManagedProxyS19.sol/AccessManagedProxyS19.json +0 -123
  28. package/build/contracts/amps/AccessManagedProxyS2.sol/AccessManagedProxyS2.json +0 -123
  29. package/build/contracts/amps/AccessManagedProxyS20.sol/AccessManagedProxyS20.json +0 -123
  30. package/build/contracts/amps/AccessManagedProxyS21.sol/AccessManagedProxyS21.json +0 -123
  31. package/build/contracts/amps/AccessManagedProxyS22.sol/AccessManagedProxyS22.json +0 -123
  32. package/build/contracts/amps/AccessManagedProxyS23.sol/AccessManagedProxyS23.json +0 -123
  33. package/build/contracts/amps/AccessManagedProxyS24.sol/AccessManagedProxyS24.json +0 -123
  34. package/build/contracts/amps/AccessManagedProxyS3.sol/AccessManagedProxyS3.json +0 -123
  35. package/build/contracts/amps/AccessManagedProxyS4.sol/AccessManagedProxyS4.json +0 -123
  36. package/build/contracts/amps/AccessManagedProxyS5.sol/AccessManagedProxyS5.json +0 -123
  37. package/build/contracts/amps/AccessManagedProxyS6.sol/AccessManagedProxyS6.json +0 -123
  38. package/build/contracts/amps/AccessManagedProxyS7.sol/AccessManagedProxyS7.json +0 -123
  39. package/build/contracts/amps/AccessManagedProxyS8.sol/AccessManagedProxyS8.json +0 -123
  40. package/build/contracts/amps/AccessManagedProxyS9.sol/AccessManagedProxyS9.json +0 -123
  41. package/contracts/amps/AccessManagedProxyS1.sol +0 -63
  42. package/contracts/amps/AccessManagedProxyS10.sol +0 -99
  43. package/contracts/amps/AccessManagedProxyS11.sol +0 -103
  44. package/contracts/amps/AccessManagedProxyS12.sol +0 -107
  45. package/contracts/amps/AccessManagedProxyS13.sol +0 -111
  46. package/contracts/amps/AccessManagedProxyS14.sol +0 -115
  47. package/contracts/amps/AccessManagedProxyS15.sol +0 -119
  48. package/contracts/amps/AccessManagedProxyS16.sol +0 -123
  49. package/contracts/amps/AccessManagedProxyS17.sol +0 -127
  50. package/contracts/amps/AccessManagedProxyS18.sol +0 -131
  51. package/contracts/amps/AccessManagedProxyS19.sol +0 -135
  52. package/contracts/amps/AccessManagedProxyS2.sol +0 -67
  53. package/contracts/amps/AccessManagedProxyS20.sol +0 -139
  54. package/contracts/amps/AccessManagedProxyS21.sol +0 -143
  55. package/contracts/amps/AccessManagedProxyS22.sol +0 -147
  56. package/contracts/amps/AccessManagedProxyS23.sol +0 -151
  57. package/contracts/amps/AccessManagedProxyS24.sol +0 -155
  58. package/contracts/amps/AccessManagedProxyS3.sol +0 -71
  59. package/contracts/amps/AccessManagedProxyS4.sol +0 -75
  60. package/contracts/amps/AccessManagedProxyS5.sol +0 -79
  61. package/contracts/amps/AccessManagedProxyS6.sol +0 -83
  62. package/contracts/amps/AccessManagedProxyS7.sol +0 -87
  63. package/contracts/amps/AccessManagedProxyS8.sol +0 -91
  64. package/contracts/amps/AccessManagedProxyS9.sol +0 -95
package/README.md CHANGED
@@ -3,13 +3,56 @@
3
3
  This repository contains the smart contract AccessManagedProxy, a proxy with built-in access control, delegating the
4
4
  permissions to an OpenZeppelin's 5.x AccessManager.
5
5
 
6
- See https://forum.openzeppelin.com/t/accessmanagedproxy-is-a-good-idea/41917/3 for a discussion on the advantages of
7
- using it.
6
+ ## 🧐 Motivation
7
+
8
+ OZ 5.x introduces the AccessManager contract and AccessManaged base contract to move the access control decisions
9
+ from code to configuration. This is a step forward compared to the 4.x AccessControl authorization framework, where
10
+ you had to make decisions in the contract mapping methods to role names.
11
+
12
+ But the AccessManaged approach falls short, because you still have to make the decision (at coding time) of which
13
+ methods to decorate with the restricted modifier.
14
+
15
+ Implementing the access control with a modifier in the methods affects the observability of the access control
16
+ configuration and its formal verification.
17
+
18
+ It also increases the test effort and makes it harder to achieve 100% branch coverage in the contracts. Finally,
19
+ this has an effect on the contract size of the implementation contracts.
20
+
21
+ The widespread use of proxy contracts (mainly for upgradeable contracts) gives us the opportunity to move the
22
+ implementation of the access control delegation logic to the AccessManager contract (that is, in the end, what the
23
+ restricted modifier does) to the proxy contract.
24
+
25
+ In this way, BEFORE doing the delegatecall to the implementation contract, we will check if the call is enabled by
26
+ calling ACCESS_MANAGER.canCall(msg.sender, address(this), selector).
27
+
28
+ For gas-optimization or other reasons, we can define a list of methods (probably the views) that will be excluded
29
+ from calling the AccessManager, reducing the overhead for non-restricted method calls to the minimum.
30
+
31
+ Another advantage of this approach is the run-time observability of the access control configuration, by checking if
32
+ a given method is included in those that skip the access control, or otherwise, we will check the access manager
33
+ configuration for that method.
34
+
35
+ More details on the motivation of this idea here: https://forum.openzeppelin.com/t/accessmanagedproxy-is-a-good-idea/41917
36
+
37
+ Also check https://www.youtube.com/watch?v=DKdwJ9Ap9vM for a presentation on this approach.
38
+
39
+ ## 📝 Details
40
+
41
+ The AccessManagedProxy contract stores the configuration in the storage (uses namespaced storage layout, see EIP-7201),
42
+ but it doesn't include in the proxy functions to modify it. The implementation contracts should add the functions to
43
+ change the access manager (`setAuthority(...)`, following IAccessManaged interface of OZ 5.x) or the passThruMethods.
44
+
45
+ The AMPUtils library includes several functions to modify the custom storage and other operations like making custom
46
+ access control checks.
47
+
48
+ Also, an AccessManagedProxyBase abstract contract is provided in case you prefer to use immutable storage or other
49
+ variants.
50
+
51
+ ## Development
8
52
 
9
53
  Try running some of the following tasks:
10
54
 
11
55
  ```shell
12
- npx hardhat help
13
- npx hardhat test
14
56
  REPORT_GAS=true npx hardhat test
57
+ npx hardhat coverage
15
58
  ```