Hats-Protocol / farcaster-delegator

A contract that owns a Farcaster fid and delegates casting rights via Hats
MIT License
20 stars 0 forks source link

Better receive logic and error codes #2

Closed spengrah closed 7 months ago

spengrah commented 7 months ago

This PR makes two primary improvements:

  1. Better logic for how the contract can receive an existing fid. It is now clearer that there are two paths:

    • a) Approving an fid upfront via prepareToReceive(). This is useful when the authorized signer(s) for the TRANSFER_TYPEHASH cannot conveniently produce a cryptographic signature for inclusion in a IdRegistry.transfer call. For example, if the the authorized signer is a contract and therefore cannot produce a cryptographic signature, or if it is an EOA that is unlikely to interact with a farcaster client that supports the other path.

    • b) Producing a valid cryptographic signature of TRANSFER_TYPEHASH-typed data, just like for other actions/typehashes

    • Supporting this change also led to more efficient logic and therefore lower gast costs for isValidSignature.

  2. More precise error codes returned by isValidSignature to facilitate better testing and troubleshooting

github-actions[bot] commented 7 months ago

Changes to gas cost

Generated at commit: 1cff2609595787bed11f78feb6253da01a9615fa, compared to commit: 84dbaad5d6055bb606d6968418d949a815f03df2

๐Ÿงพ Summary (10% most significant diffs)

Contract Method Avg (+/-) %
HatsFarcasterDelegator isValidSignature -6,066 โœ… -24.13%
MockFarcasterDelegator isValidSignature -69 โœ… -0.84%

Full diff report ๐Ÿ‘‡
| Contract | Deployment Cost (+/-) | Method | Min (+/-) | % | Avg (+/-) | % | Median (+/-) | % | Max (+/-) | % | # Calls (+/-) | |:-|-:|:-|-:|-:|-:|-:|-:|-:|-:|-:|-:| | **HatsFarcasterDelegator** | 1,690,893 (+16,014) | _isValidSignature_ | 978 (-5,060) | **-83.80%** | 19,073 (-6,066) | **-24.13%** | 25,271 (-120) | **-0.47%** | 36,872 (-15) | **-0.04%** | 21 (+7) | | **MockFarcasterDelegator** | 1,294,756 (+16,013) | _addKey_
_isValidSignature_ | 160,542 (-16)
2,370 (-3,640) | **-0.01%**
**-60.57%** | 169,292 (-16)
8,157 (-69) | **-0.01%**
**-0.84%** | 169,292 (-16)
9,318 (+984) | **-0.01%**
**+11.81%** | 178,042 (-16)
11,624 (+1,290) | **-0.01%**
**+12.48%** | 2 (0)
4 (+1) |