@@ -35,3 +35,56 @@ Contract protecting the implementation only needs to implement a [IERC7746](http
35
35
Drainer contract calls victim number of times defined by Drainer function input.
36
36
37
37
In the particular implementation rate is limited to 10 transactions per block and can be tested by ` pnpm test `
38
+
39
+
40
+ ## Implementing your layer
41
+
42
+ Layer contract should only implement simple ILayer interface:
43
+
44
+ ``` solidity
45
+ // SPDX-License-Identifier: CC0-1.0
46
+ pragma solidity >=0.8.0 <0.9.0;
47
+
48
+ interface IERC7746 {
49
+ /// @notice Validates a function call before execution.
50
+ /// @param configuration Layer-specific configuration data.
51
+ /// @param selector The function selector being called.
52
+ /// @param sender The address initiating the call.
53
+ /// @param value The amount of ETH sent with the call (if any).
54
+ /// @param data The calldata for the function call.
55
+ /// @return beforeCallResult Arbitrary data to be passed to `afterCallValidation`.
56
+ /// @dev MUST revert if validation fails.
57
+ function beforeCall(
58
+ bytes memory configuration,
59
+ bytes4 selector,
60
+ address sender,
61
+ uint256 value,
62
+ bytes memory data
63
+ ) external returns (bytes memory);
64
+
65
+ /// @notice Validates a function call after execution.
66
+ /// @param configuration Layer-specific configuration data.
67
+ /// @param selector The function selector being called.
68
+ /// @param sender The address initiating the call.
69
+ /// @param value The amount of ETH sent with the call (if any).
70
+ /// @param data The calldata for the function call.
71
+ /// @param beforeCallResult The data returned by `beforeCallValidation`.
72
+ /// @dev MUST revert if validation fails.
73
+ function afterCall(
74
+ bytes memory configuration,
75
+ bytes4 selector,
76
+ address sender,
77
+ uint256 value,
78
+ bytes memory data,
79
+ bytes memory beforeCallResult
80
+ ) external;
81
+ }
82
+ ```
83
+ ## Protecting with a layer
84
+
85
+ 1 . Add layers per your needs (in constructor, initializer etc)
86
+ 2 . Wrap protected state access with layer modifier (fallback function for proxies)
87
+
88
+ Reference implementation of [ MiddlewareProxy] ( https://github.com/peersky/smart-contract-layers/blob/main/src/MiddlewareProxy.sol ) :
89
+
90
+
0 commit comments