Skip to content

Commit dbe87be

Browse files
committed
Distributor when doing checks now always infers real target address from config to accommodate for middlewares such as access manager intermediate contract
1 parent 0b61cff commit dbe87be

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

.changeset/thick-poems-remember.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@peeramid-labs/eds": major
3+
---
4+
5+
Distributor when doing checks now always infers real target address from config to accommodate for middlewares such as access manager intermediate contract

src/abstracts/Distributor.sol

+11-5
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ abstract contract Distributor is IDistributor, CodeIndexer, ERC165 {
7373
);
7474
require(success, string(result));
7575
}
76+
numInstances++;
7677
uint256 instanceId = numInstances;
7778
for (uint256 i = 0; i < instances.length; i++) {
7879
instanceIds[instances[i]] = instanceId;
7980
distributionOf[instanceId] = distributorsId;
8081
}
81-
emit Instantiated(distributorsId, args, instances);
82+
emit Instantiated(distributorsId, instanceId, args, instances);
8283
return (instances, distributionName, distributionVersion);
8384
}
8485

@@ -91,16 +92,17 @@ abstract contract Distributor is IDistributor, CodeIndexer, ERC165 {
9192
* it will revert if instanceId belongs to disactivated distribution
9293
*/
9394
function beforeCall(
94-
bytes memory,
95+
bytes memory config,
9596
bytes4,
9697
address maybeInstance,
9798
uint256,
9899
bytes memory
99100
) public view virtual returns (bytes memory) {
101+
(address target) = abi.decode(config, (address));
100102
bytes32 distributorsId = distributionOf[getInstanceId(maybeInstance)];
101103
if (
102104
distributorsId != bytes32(0) &&
103-
getInstanceId(msg.sender) == getInstanceId(maybeInstance) &&
105+
getInstanceId(target) == getInstanceId(maybeInstance) &&
104106
distirbutionsSet.contains(distributorsId) == true
105107
) {
106108
// ToDo: This check could be based on DistributionOf, hence allowing cross-instance calls
@@ -111,15 +113,19 @@ abstract contract Distributor is IDistributor, CodeIndexer, ERC165 {
111113
}
112114

113115
function afterCall(
114-
bytes memory,
116+
bytes memory config,
115117
bytes4,
116118
address maybeInstance,
117119
uint256,
118120
bytes memory,
119121
bytes memory
120122
) public virtual {
123+
(address target) = abi.decode(config, (address));
121124
bytes32 distributorsId = distributionOf[getInstanceId(maybeInstance)];
122-
if (getInstanceId(msg.sender) != getInstanceId(maybeInstance) && distirbutionsSet.contains(distributorsId) == true) {
125+
if (
126+
(getInstanceId(target) != getInstanceId(maybeInstance)) &&
127+
distirbutionsSet.contains(distributorsId) == true
128+
) {
123129
revert InvalidInstance(maybeInstance);
124130
}
125131
}

src/interfaces/IDistributor.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface IDistributor is IERC7746, IERC165 {
1010
error DistributionExists(bytes32 id);
1111
error InitializerNotFound(bytes32 id);
1212
error InvalidInstance(address instance);
13-
event Instantiated(bytes32 indexed distributionId, bytes indexed argsHash, address[] instances);
13+
event Instantiated(bytes32 indexed distributionId,uint256 indexed instanceId, bytes indexed argsHash, address[] instances);
1414
event DistributionRemoved(bytes32 indexed id);
1515

1616
event DistributionAdded(bytes32 indexed id, address indexed initializer);

src/managers/SimpleAccessManager.sol

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {IERC7746} from "../interfaces/IERC7746.sol";
66
import {IDistributor} from "../interfaces/IDistributor.sol";
77
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
88
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
9-
109
contract SimpleAccessManager is Initializable, IERC7746, ERC165 {
1110
struct MethodSettings {
1211
bool isDistributionOnly;
@@ -62,7 +61,7 @@ contract SimpleAccessManager is Initializable, IERC7746, ERC165 {
6261
}
6362

6463
function beforeCall(
65-
bytes memory configuration,
64+
bytes memory ,
6665
bytes4 selector,
6766
address sender,
6867
uint256 value,
@@ -76,14 +75,14 @@ contract SimpleAccessManager is Initializable, IERC7746, ERC165 {
7675
revert("SimpleAccessManager: sender is not allowed to call this method");
7776
} else {
7877
if (s.methodSettings[selector].isDistributionOnly) {
79-
return s.distributor.beforeCall(configuration, selector, sender, value, data);
78+
return s.distributor.beforeCall(abi.encode(msg.sender), selector, sender, value, data);
8079
}
8180
return "";
8281
}
8382
}
8483

8584
function afterCall(
86-
bytes memory configuration,
85+
bytes memory ,
8786
bytes4 selector,
8887
address sender,
8988
uint256 value,
@@ -95,7 +94,7 @@ contract SimpleAccessManager is Initializable, IERC7746, ERC165 {
9594
revert("ERC20DistributorsManager: only target can call this function");
9695
}
9796
if (s.methodSettings[selector].isDistributionOnly) {
98-
s.distributor.afterCall(configuration, selector, sender, value, data,beforeCallResult);
97+
s.distributor.afterCall(abi.encode(msg.sender), selector, sender, value, data,beforeCallResult);
9998
}
10099
}
101100

0 commit comments

Comments
 (0)