Skip to content

Commit 9433af5

Browse files
committed
feat: fix trusted attester linked list clearing
1 parent 17d1e4e commit 9433af5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/core/TrustManager.sol

+17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ abstract contract TrustManager is IRegistry {
2727

2828
mapping(address account => TrustedAttesterRecord attesters) internal $accountToAttester;
2929

30+
function _requireEmptyList(TrustedAttesterRecord storage $trustedAttester) internal view {
31+
address _tmp = $trustedAttester.attester;
32+
33+
// if the first entry is zero, the trusted list was not previously initialized, and can thus be safely set.
34+
if (_tmp == ZERO_ADDRESS) return;
35+
36+
// otherwise, loop over the linked list to check if it is empty
37+
// find the last entry in the linked list.
38+
for (uint256 i; i <= type(uint8).max; i++) {
39+
_tmp = $trustedAttester.linkedAttesters[_tmp][msg.sender];
40+
if (_tmp == ZERO_ADDRESS) return;
41+
}
42+
}
43+
3044
/**
3145
* @inheritdoc IERC7484
3246
*/
@@ -49,6 +63,9 @@ abstract contract TrustManager is IRegistry {
4963
revert InvalidThreshold();
5064
}
5165

66+
// ensure that the trusted attester list is cleared before re-initializing it.
67+
_requireEmptyList($trustedAttester);
68+
5269
$trustedAttester.attesterCount = uint8(attestersLength);
5370
$trustedAttester.threshold = threshold;
5471
$trustedAttester.attester = attesters[0];

test/TrustedAttesterList.t.sol

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
import "./Attestation.t.sol";
5+
import "src/DataTypes.sol";
6+
import { LibSort } from "solady/utils/LibSort.sol";
7+
8+
contract POCTest is AttestationTest {
9+
using LibSort for address[];
10+
11+
function setUp() public override {
12+
super.setUp();
13+
}
14+
15+
function testPOC() external prankWithAccount(smartAccount1) {
16+
uint8 threshold = 1;
17+
address[] memory trustedAttesters = new address[](3);
18+
trustedAttesters[0] = address(attester1.addr);
19+
trustedAttesters[1] = address(attester2.addr);
20+
trustedAttesters[2] = makeAddr("attester3");
21+
22+
trustedAttesters.sort();
23+
trustedAttesters.uniquifySorted();
24+
25+
registry.trustAttesters(threshold, trustedAttesters);
26+
27+
address[] memory result = registry.findTrustedAttesters(smartAccount1.addr);
28+
29+
assertEq(result.length, trustedAttesters.length);
30+
for (uint256 i; i < trustedAttesters.length; i++) {
31+
assertEq(result[i], trustedAttesters[i]);
32+
}
33+
34+
_make_WhenUsingValidECDSA(attester2);
35+
registry.check(address(module1), ModuleType.wrap(1));
36+
37+
address[] memory newTrustedAttesters = new address[](1);
38+
newTrustedAttesters[0] = address(attester1.addr);
39+
registry.trustAttesters(1, newTrustedAttesters);
40+
address[] memory newResult = registry.findTrustedAttesters(smartAccount1.addr);
41+
assertEq(newResult.length, 1);
42+
assertEq(newResult[0], address(attester1.addr));
43+
44+
registry.check(address(module1), ModuleType.wrap(1));
45+
}
46+
}

0 commit comments

Comments
 (0)