Skip to content

Commit

Permalink
gas
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroknots committed Feb 13, 2024
1 parent 1521cb6 commit 2b5ba63
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
38 changes: 19 additions & 19 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
AttestationTest:test_WhenAttestingToNon_existingModule(address,uint48,bytes,uint32[]) (runs: 256, μ: 23693, ~: 23329)
AttestationTest:test_WhenAttestingWithExpirationTimeInThePast(address,bytes,uint32) (runs: 256, μ: 16592, ~: 16549)
AttestationTest:test_WhenAttestingWithNoAttestationData() (gas: 275817)
AttestationTest:test_WhenAttestingToNon_existingModule(address,uint48,bytes,uint32[]) (runs: 256, μ: 23689, ~: 23329)
AttestationTest:test_WhenAttestingWithExpirationTimeInThePast(address,bytes,uint32) (runs: 256, μ: 16593, ~: 16549)
AttestationTest:test_WhenAttestingWithNoAttestationData() (gas: 275618)
AttestationTest:test_WhenAttestingWithTooHighModuleType(address,uint48,bytes,uint32) (runs: 256, μ: 18309, ~: 18706)
AttestationTest:test_WhenAttesting_ShouldCallResolver() (gas: 180325)
AttestationTest:test_WhenReAttestingToARevokedAttestation() (gas: 336670)
AttestationTest:test_WhenReAttestingToARevokedAttestation() (gas: 336471)
AttestationTest:test_WhenRevokingAttestationThatDoesntExist(address) (runs: 256, μ: 28098, ~: 28098)
AttestationTest:test_WhenRevokingWithValidECDSA() (gas: 240190)
AttestationTest:test_WhenRevokingWithValidECDSAMulti() (gas: 409757)
Expand All @@ -17,19 +17,19 @@ AttestationTest:test_WhenUsingValidECDSA() (gas: 224126)
AttestationTest:test_WhenUsingValidECDSAMulti() (gas: 385144)
AttestationTest:test_WhenUsingValidERC1271() (gas: 211437)
AttestationTest:test_WhenUsingValidERC1271Multi() (gas: 371364)
ImmutableData:invariant_attestation_immutable() (runs: 1200, calls: 24000, reverts: 7296)
ImmutableData:invariant_balance() (runs: 1200, calls: 24000, reverts: 7296)
ImmutableData:invariant_resolver_immutable() (runs: 1200, calls: 24000, reverts: 7296)
ImmutableData:invariant_schema_immutable() (runs: 1200, calls: 24000, reverts: 7296)
ModuleRegistrationTest:test_WhenDeployingViaRegistry() (gas: 130600)
ModuleRegistrationTest:test_WhenDeployingViaRegistryWithArgs() (gas: 153719)
ImmutableData:invariant_attestation_immutable() (runs: 1200, calls: 24000, reverts: 7425)
ImmutableData:invariant_balance() (runs: 1200, calls: 24000, reverts: 7425)
ImmutableData:invariant_resolver_immutable() (runs: 1200, calls: 24000, reverts: 7425)
ImmutableData:invariant_schema_immutable() (runs: 1200, calls: 24000, reverts: 7425)
ModuleRegistrationTest:test_WhenDeployingViaRegistry() (gas: 130398)
ModuleRegistrationTest:test_WhenDeployingViaRegistryWithArgs() (gas: 153516)
ModuleRegistrationTest:test_WhenRegisteringAModuleOnAInValidResolverUID() (gas: 74823)
ModuleRegistrationTest:test_WhenRegisteringAModuleOnAValidResolverUID() (gas: 105929)
ModuleRegistrationTest:test_WhenRegisteringAModuleOnAValidResolverUID() (gas: 105730)
ModuleRegistrationTest:test_WhenRegisteringAModuleOnAnInvalidResolverUID() (gas: 81381)
ModuleRegistrationTest:test_WhenRegisteringTwoModulesWithTheSameBytecode() (gas: 108758)
ModuleRegistrationTest:test_WhenRegisteringViaFactory() (gas: 223998)
ModuleRegistrationTest:test_WhenUsingInvalidFactory() (gas: 18581)
ModuleRegistrationTest:test_WhenUsingRegistryASFactory() (gas: 15736)
ModuleRegistrationTest:test_WhenRegisteringTwoModulesWithTheSameBytecode() (gas: 108559)
ModuleRegistrationTest:test_WhenRegisteringViaFactory() (gas: 219570)
ModuleRegistrationTest:test_WhenUsingInvalidFactory() (gas: 16406)
ModuleRegistrationTest:test_WhenUsingRegistryASFactory() (gas: 13561)
ResolverTest:test_WhenNewResolver() (gas: 285233)
ResolverTest:test_WhenResolverAlreadyRegistered() (gas: 282816)
ResolverTest:test_WhenUsingAuthorizedAccount() (gas: 511780)
Expand All @@ -41,15 +41,15 @@ TrustTest:test_WhenAttestersSetAndAllOk() (gas: 285080)
TrustTest:test_WhenAttestersSetButThresholdTooLow() (gas: 188)
TrustTest:test_WhenAttestingToNon_existingModule(address,uint48,bytes,uint32[]) (runs: 256, μ: 23718, ~: 23357)
TrustTest:test_WhenAttestingWithExpirationTimeInThePast(address,bytes,uint32) (runs: 256, μ: 16570, ~: 16527)
TrustTest:test_WhenAttestingWithNoAttestationData() (gas: 275795)
TrustTest:test_WhenAttestingWithTooHighModuleType(address,uint48,bytes,uint32) (runs: 256, μ: 18331, ~: 18728)
TrustTest:test_WhenAttestingWithNoAttestationData() (gas: 275596)
TrustTest:test_WhenAttestingWithTooHighModuleType(address,uint48,bytes,uint32) (runs: 256, μ: 18480, ~: 18728)
TrustTest:test_WhenAttesting_ShouldCallResolver() (gas: 180392)
TrustTest:test_WhenNoAttestersSet() (gas: 39131)
TrustTest:test_WhenReAttestingToARevokedAttestation() (gas: 336692)
TrustTest:test_WhenReAttestingToARevokedAttestation() (gas: 336493)
TrustTest:test_WhenRevokingAttestationThatDoesntExist(address) (runs: 256, μ: 28120, ~: 28120)
TrustTest:test_WhenRevokingWithValidECDSA() (gas: 240168)
TrustTest:test_WhenRevokingWithValidECDSAMulti() (gas: 409823)
TrustTest:test_WhenSupplyingManyAttesters(address[]) (runs: 256, μ: 1327355, ~: 1326333)
TrustTest:test_WhenSupplyingManyAttesters(address[]) (runs: 256, μ: 1326050, ~: 1326696)
TrustTest:test_WhenSupplyingOneAttester() (gas: 42650)
TrustTest:test_WhenSupplyingSameAttesterMultipleTimes() (gas: 13159)
TrustTest:test_WhenTokensAreNotPaid() (gas: 210)
Expand Down
2 changes: 1 addition & 1 deletion src/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ struct AttestationRecord {
uint48 expirationTime; // The time when the attestation expires (Unix timestamp).
uint48 revocationTime; // The time when the attestation was revoked (Unix timestamp).
PackedModuleTypes moduleTypes; // bit-wise encoded module types. See ModuleTypeLib
SchemaUID schemaUID; // The unique identifier of the schema.
address moduleAddr; // The implementation address of the module that is being attested.
address attester; // The attesting account.
AttestationDataRef dataPointer; // SSTORE2 pointer to the attestation data.
SchemaUID schemaUID; // The unique identifier of the schema.
}

// Struct that represents Module artefact.
Expand Down
7 changes: 2 additions & 5 deletions src/IRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,7 @@ interface IRegistry is IERC7484 {
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// Event triggered when a module is deployed.
event ModuleRegistration(
address indexed implementation, address indexed sender, bytes32 resolver
);
event ModuleDeployed(address indexed implementation, bytes32 indexed salt, bytes32 resolver);
event ModuleDeployedExternalFactory(
address indexed implementation, address indexed factory, bytes32 resolver
address indexed implementation, address indexed sender, ResolverUID resolverUID
);

error AlreadyRegistered(address module);
Expand Down Expand Up @@ -355,6 +351,7 @@ interface IRegistry is IERC7484 {
* Schemas describe the structure of the data of attestations
* every attestation made on this registry, will reference a SchemaUID to
* make it possible to decode attestation data in human readable form
* overrwriting a schema is not allowed, and will revert
* @param schema ABI schema used to encode attestations that are made with this schema
* @param validator (optional) external schema validator that will be used to validate attestations.
* use address(0), if you dont need an external validator
Expand Down
9 changes: 6 additions & 3 deletions src/core/ModuleManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
ResolverRecord storage $resolver = resolvers[resolverUID];
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);

// address predictedModuleAddress = code.calculateAddress(deployParams, salt);

moduleAddress = initCode.deploy(salt);
// _storeModuleRecord() will check if module is already registered,
// which should prevent reentry to any deploy function
Expand All @@ -62,6 +60,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
resolverUID: resolverUID,
metadata: metadata
});

record.requireExternalResolverOnModuleRegistration({
moduleAddress: moduleAddress,
$resolver: $resolver
Expand Down Expand Up @@ -178,7 +177,11 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
_moduleAddrToRecords[moduleAddress] = moduleRegistration;

// Emit ModuleRegistration event
emit ModuleRegistration(moduleAddress, sender, ResolverUID.unwrap(resolverUID));
emit ModuleRegistration({
implementation: moduleAddress,
sender: sender,
resolverUID: resolverUID
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/core/SchemaManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract contract SchemaManager is IRegistry {
*/
function registerSchema(
string calldata schema,
IExternalSchemaValidator validator // OPTIONAL
IExternalSchemaValidator validator
)
external
onlySchemaValidator(validator)
Expand All @@ -40,6 +40,8 @@ abstract contract SchemaManager is IRegistry {
// Computing a unique ID for the schema using its properties
uid = schemaRecord.getUID();

// check if schema with this UID already exists.
// overwriting a schema is not allowed
if (schemas[uid].registeredAt != ZERO_TIMESTAMP) revert SchemaAlreadyExists(uid);

// Storing schema in the _schemas mapping
Expand Down
3 changes: 1 addition & 2 deletions src/core/TrustManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,17 @@ abstract contract TrustManager is IRegistry, TrustManagerExternalAttesterList {
*/
function trustAttesters(uint8 threshold, address[] memory attesters) external {
uint256 attestersLength = attesters.length;
// sort attesters and remove duplicates
attesters.sort();
attesters.uniquifySorted();
if (attestersLength == 0) revert InvalidTrustedAttesterInput();
if (attesters.length != attestersLength) revert InvalidTrustedAttesterInput();
// sort attesters

TrustedAttesterRecord storage $trustedAttester = _accountToAttester[msg.sender];
// threshold cannot be greater than the number of attesters
if (threshold > attestersLength) {
threshold = uint8(attestersLength);
}
//
$trustedAttester.attesterCount = uint8(attestersLength);
$trustedAttester.threshold = threshold;
$trustedAttester.attester = attesters[0];
Expand Down
2 changes: 0 additions & 2 deletions src/lib/AttestationLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ library AttestationLib {
pure
returns (bytes32 _hash)
{
// TODO: check if this is correct
_hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(data)), nonce));
}

Expand All @@ -76,7 +75,6 @@ library AttestationLib {
pure
returns (bytes32 _hash)
{
// TODO: check if this is correct
_hash = keccak256(abi.encode(REVOKE_TYPEHASH, keccak256(abi.encode(data)), nonce));
}
}

0 comments on commit 2b5ba63

Please sign in to comment.