Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make trust attesters 4337 compliant #65

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"forge-std": "github:foundry-rs/forge-std#v1.7.6",
"solady": "github:vectorized/solady#9deb9ed36a27261a8745db5b7cd7f4cdc3b1cd4e",
"solhint": "^4.5.2",
"solmate": "github:transmissions11/solmate#c892309933b25c03d32b1b0d674df7ae292ba925"
"solmate": "github:transmissions11/solmate#c892309933b25c03d32b1b0d674df7ae292ba925",
"@rhinestone/erc4337-validation": "github:rhinestonewtf/erc4337-validation"
},
"files": [
"artifacts",
Expand Down
5,907 changes: 4,623 additions & 1,284 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ solmate/=node_modules/solmate/src/
solady/=node_modules/solady/src/
forge-std/=node_modules/forge-std/src/
ds-test/=node_modules/ds-test/src/
erc4337-validation/=node_modules/@rhinestone/erc4337-validation/src/

account-abstraction/=node_modules/account-abstraction/contracts/
account-abstraction-v0.6/=node_modules/account-abstraction-v0.6/contracts/
@openzeppelin/=node_modules/@openzeppelin/
2 changes: 1 addition & 1 deletion src/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct TrustedAttesterRecord {
uint8 attesterCount; // number of attesters in the linked list
uint8 threshold; // minimum number of attesters required
address attester; // first attester in linked list. (packed to save gas)
mapping(address attester => address linkedAttester) linkedAttesters; // linked list
mapping(address attester => mapping(address account => address linkedAttester)) linkedAttesters; // 4337-compliant linked list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually quite elegant hack

}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
Expand Down
6 changes: 3 additions & 3 deletions src/core/TrustManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ abstract contract TrustManager is IRegistry {
address _attester = attesters[i];
// user could have set attester to address(0)
if (_attester == ZERO_ADDRESS) revert InvalidTrustedAttesterInput();
$trustedAttester.linkedAttesters[_attester] = attesters[i + 1];
$trustedAttester.linkedAttesters[_attester][msg.sender] = attesters[i + 1];
}

emit NewTrustedAttesters();
Expand Down Expand Up @@ -129,7 +129,7 @@ abstract contract TrustManager is IRegistry {

for (uint256 i = 1; i < attesterCount; i++) {
// get next attester from linked List
attester = $trustedAttesters.linkedAttesters[attester];
attester = $trustedAttesters.linkedAttesters[attester][smartAccount];
$attestation = $getAttestation({ module: module, attester: attester });
if ($attestation.checkValid(moduleType)) threshold--;

Expand All @@ -154,7 +154,7 @@ abstract contract TrustManager is IRegistry {

for (uint256 i = 1; i < count; i++) {
// get next attester from linked List
attesters[i] = $trustedAttesters.linkedAttesters[attesters[i - 1]];
attesters[i] = $trustedAttesters.linkedAttesters[attesters[i - 1]][smartAccount];
}
}

Expand Down
33 changes: 32 additions & 1 deletion test/TrustDelegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ pragma solidity ^0.8.0;
import "./Attestation.t.sol";
import "src/DataTypes.sol";
import { LibSort } from "solady/utils/LibSort.sol";
import { VmSafe } from "forge-std/Vm.sol";
import { ERC4337SpecsParser } from "erc4337-validation/SpecsParser.sol";

contract TrustTest is AttestationTest {
using LibSort for address[];
using ERC4337SpecsParser for VmSafe.AccountAccess;

function setUp() public override {
super.setUp();
Expand All @@ -31,7 +34,7 @@ contract TrustTest is AttestationTest {
uint8 threshold,
address[] memory attesters
)
external
public
whenSettingAttester
prankWithAccount(smartAccount1)
{
Expand Down Expand Up @@ -123,4 +126,32 @@ contract TrustTest is AttestationTest {
vm.expectRevert();
registry.check(address(module1), ModuleType.wrap(3));
}

function test_WhenSupplyingManyAttesters_ShouldBe4337Compliant(uint8 threshold, address[] memory attesters) public {
vm.startMappingRecording();
vm.startStateDiffRecording();

test_WhenSupplyingManyAttesters(threshold, attesters);

VmSafe.AccountAccess[] memory accesses = vm.stopAndReturnStateDiff();

ERC4337SpecsParser.Entities memory entities = ERC4337SpecsParser.Entities({
account: smartAccount1.addr,
factory: address(0),
isFactoryStaked: false,
paymaster: address(0),
isPaymasterStaked: false,
aggregator: address(0),
isAggregatorStaked: false
});

for (uint256 i; i < accesses.length; i++) {
VmSafe.AccountAccess memory currentAccess = accesses[i];
if (currentAccess.account != address(this) && currentAccess.accessor != address(this)) {
currentAccess.validateBannedStorageLocations(entities);
}
}

vm.stopMappingRecording();
}
}
Loading