farcasterxyz / contracts

Implementation of the Farcaster contracts
https://www.farcaster.xyz/
MIT License
340 stars 122 forks source link

feat(KeyRegistry): validate key metadata #354

Closed horsefacts closed 1 year ago

horsefacts commented 1 year ago

Motivation

We'd like to validate signer key metadata on chain when a new signer key is registered. See FIP-7 and the comment here on the "Application Identifiers" FIP for more details.

Change Summary

Introduce "validator" contracts to the key registry. A validator must implement the IMetadataValidator interface. The KeyRegistry looks up the registered validator by keyType and metadataType and calls it to validate signer key metadata inside _add, ensuring that only keys with valid metadata can be registered onchain.

Merge Checklist

Choose all relevant options below by adding an x now or at any time before submitting for review

Additional context

Add a KeyRegistry.integration.t.sol test, which tests using an actual AppIdValidator rather than a stubbed version.


PR-Codex overview

Focus of the PR:

This PR focuses on adding a new interface IMetadataValidator and making changes related to gas usage in various test cases.

Detailed summary:

The following files were skipped due to too many changes: src/Bundler.sol, test/KeyRegistry/KeyRegistry.integration.t.sol, test/Deploy/Deploy.t.sol, src/validators/SignedKeyRequestValidator.sol, test/validators/SignedKeyRequestValidator/SignedKeyRequestValidator.t.sol, test/Bundler/Bundler.t.sol, src/KeyRegistry.sol, test/KeyRegistry/KeyRegistry.t.sol

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

horsefacts commented 1 year ago

@varunsrin Updated with an explicit metadataType arg and the naming conventions from FIP-7. This was a big rename refactor, so I'd appreciate a review to make sure I caught everything!

github-actions[bot] commented 1 year ago

Coverage after merging horsefacts/app-id-validators into main will be

98.86%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   Bundler.sol100%100%100%100%
   FnameResolver.sol100%100%100%100%
   IdRegistry.sol100%100%100%100%
   KeyRegistry.sol100%100%100%100%
   StorageRegistry.sol100%100%100%100%
src/lib
   Signatures.sol100%100%100%100%
   TransferHelper.sol0%0%0%0%12, 17, 20, 20, 20
   TrustedCaller.sol100%100%100%100%
src/validators
   SignedKeyRequestValidator.sol100%100%100%100%