diff --git a/.gitignore b/.gitignore index 259c931..67e182f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Compiler files cache/ out/ +out-optimized/ .DS_Store docs/ diff --git a/src/lib/AttestationLib.sol b/src/lib/AttestationLib.sol index b136d9c..3ce69fd 100644 --- a/src/lib/AttestationLib.sol +++ b/src/lib/AttestationLib.sol @@ -6,18 +6,21 @@ import { SSTORE2 } from "solady/utils/SSTORE2.sol"; library AttestationLib { // The hash of the data type used to relay calls to the attest function. It's the value of - bytes32 internal constant ATTEST_REQUEST_TYPEHASH = keccak256("AttestationRequest(address,uint48,bytes,uint256[])"); - bytes32 internal constant ATTEST_TYPEHASH = - keccak256("SignedAttestationRequest(AttestationRequest,uint256 nonce)AttestationRequest(address,uint48,bytes,uint256[])"); - bytes32 internal constant ATTEST_ARRAY_TYPEHASH = - keccak256("SignedAttestationRequests(AttestationRequest[],uint256 nonce)AttestationRequest(address,uint48,bytes,uint256[])"); + bytes32 internal constant ATTEST_REQUEST_TYPEHASH = + keccak256("AttestationRequest(address moduleAddress,uint48 expirationTime,bytes data,uint256[] moduleTypes)"); + bytes32 internal constant ATTEST_TYPEHASH = keccak256( + "SignedAttestationRequest(AttestationRequest,uint256 nonce)AttestationRequest(address moduleAddress,uint48 expirationTime,bytes data,uint256[] moduleTypes)" + ); + bytes32 internal constant ATTEST_ARRAY_TYPEHASH = keccak256( + "SignedAttestationRequests(AttestationRequest[],uint256 nonce)AttestationRequest(address moduleAddress,uint48 expirationTimme,bytes data,uint256[] moduleTypes)" + ); // The hash of the data type used to relay calls to the revoke function. It's the value of - bytes32 internal constant REVOKE_REQUEST_TYPEHASH = keccak256("RevocationRequest(address)"); + bytes32 internal constant REVOKE_REQUEST_TYPEHASH = keccak256("RevocationRequest(address moduleAddress)"); bytes32 internal constant REVOKE_TYPEHASH = - keccak256("SignedRevocationRequest(RevocationRequest,uint256 nonce)RevocationRequest(address)"); + keccak256("SignedRevocationRequest(RevocationRequest,uint256 nonce)RevocationRequest(address moduleAddress)"); bytes32 internal constant REVOKE_ARRAY_TYPEHASH = - keccak256("SignedRevocationRequests(RevocationRequest[],uint256 nonce)RevocationRequest(address)"); + keccak256("SignedRevocationRequests(RevocationRequest[],uint256 nonce)RevocationRequest(address moduleAddressq)"); /** * Helper function to SSTORE2 read an attestation @@ -64,7 +67,21 @@ library AttestationLib { * @return _hash the hash */ function hash(AttestationRequest calldata request, uint256 nonce) internal pure returns (bytes32 _hash) { - _hash = keccak256(abi.encode(ATTEST_TYPEHASH, keccak256(abi.encode(request)), nonce)); + _hash = keccak256( + abi.encode( + ATTEST_TYPEHASH, + keccak256( + abi.encode( + ATTEST_REQUEST_TYPEHASH, + request.moduleAddr, + request.expirationTime, + keccak256(request.data), + keccak256(abi.encodePacked(request.moduleTypes)) + ) + ), + nonce + ) + ); } /** @@ -74,7 +91,25 @@ library AttestationLib { * @return _hash the hash */ function hash(AttestationRequest[] calldata requests, uint256 nonce) internal pure returns (bytes32 _hash) { - _hash = keccak256(abi.encode(ATTEST_ARRAY_TYPEHASH, keccak256(abi.encode(requests)), nonce)); + bytes memory concatinatedAttestations; + + uint256 length = requests.length; + for (uint256 i; i < length; i++) { + concatinatedAttestations = abi.encodePacked( + concatinatedAttestations, // concat previous + keccak256( + abi.encode( + ATTEST_REQUEST_TYPEHASH, + requests[i].moduleAddr, + requests[i].expirationTime, + keccak256(requests[i].data), + keccak256(abi.encodePacked(requests[i].moduleTypes)) + ) + ) + ); + } + + _hash = keccak256(abi.encode(ATTEST_ARRAY_TYPEHASH, keccak256(concatinatedAttestations), nonce)); } /** @@ -84,7 +119,7 @@ library AttestationLib { * @return _hash the hash */ function hash(RevocationRequest calldata request, uint256 nonce) internal pure returns (bytes32 _hash) { - _hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(request)), nonce)); + _hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(REVOKE_REQUEST_TYPEHASH, request.moduleAddr)), nonce)); } /** @@ -94,6 +129,16 @@ library AttestationLib { * @return _hash the hash */ function hash(RevocationRequest[] calldata requests, uint256 nonce) internal pure returns (bytes32 _hash) { - _hash = keccak256(abi.encode(REVOKE_ARRAY_TYPEHASH, keccak256(abi.encode(requests)), nonce)); + bytes memory concatinatedAttestations; + + uint256 length = requests.length; + for (uint256 i; i < length; i++) { + concatinatedAttestations = abi.encodePacked( + concatinatedAttestations, // concat previous + keccak256(abi.encode(REVOKE_REQUEST_TYPEHASH, requests[i].moduleAddr)) + ); + } + + _hash = keccak256(abi.encode(REVOKE_ARRAY_TYPEHASH, keccak256(concatinatedAttestations), nonce)); } } diff --git a/test/ModuleRegistration.t.sol b/test/ModuleRegistration.t.sol index 6242429..89f61d2 100644 --- a/test/ModuleRegistration.t.sol +++ b/test/ModuleRegistration.t.sol @@ -45,12 +45,11 @@ contract ModuleRegistrationTest is BaseTest { ResolverUID invalidUID = ResolverUID.wrap(hex"00"); vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidResolverUID.selector, invalidUID)); - registry.registerModule(invalidUID, address(newModule), ""); + registry.registerModule(invalidUID, address(newModule), "", ""); invalidUID = ResolverUID.wrap("1"); vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidResolverUID.selector, invalidUID)); - registry.registerModule(invalidUID, address(newModule), ""); - + registry.registerModule(invalidUID, address(newModule), "", ""); } function test_WhenRegisteringAModuleOnAValidResolverUID() external prankWithAccount(moduleDev1) { @@ -66,8 +65,7 @@ contract ModuleRegistrationTest is BaseTest { MockModule newModule = new MockModule(); vm.expectRevert(abi.encodeWithSelector(IRegistry.InvalidResolverUID.selector, ResolverUID.wrap(bytes32("foobar")))); - registry.registerModule(ResolverUID.wrap(bytes32("foobar")), address(newModule), ""); - + registry.registerModule(ResolverUID.wrap(bytes32("foobar")), address(newModule), "", ""); } function test_WhenRegisteringTwoModulesWithTheSameBytecode() external prankWithAccount(moduleDev1) {