FIP-10: Gateways #133
varunsrin
announced in
FIP Stage 4: Finalized
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Title: Gateways
Type: Implementation FIP
Author: @horsefacts, @sanjayprabhu, @varunsrin
Abstract
Farcaster contracts are redeployed with improvements to read state from the blockchain. The main changes are:
Problem
Farcaster contracts emit events which are consumed by downstream apps. Apps will create a database row when they see
register
on IdRegistry andadd
on KeyRegistry. Since OP Mainnet gas is cheap, malicious actors can spend < $100k to add millions of events. It’s possible to lazily ingest events, but this raises the barrier to creating new apps.Event spam can be resolved by changing the logic around registration of identities and keys. But such changes requires a contract redeployment which is expensive and time consuming. We may run into such issues again, and it would be ideal to not have to redeploy the contract each time.
Specification
We propose separating contract methods into two categories:
Registration methods can only be called via a gateway contract which can implement additional limitations. The contract is swappable and the rules can be changed by the admins.
Transfer methods must never implement a gateway and remain immutable for the life of the contract. Once someone registers an asset it cannot change hands without their permission. This ensures the system remains sufficiently decentralized.
We propose classifying IdRegistry’s
register
,registerFor
and KeyRegistry’sadd
andaddFor
as registration methods, as shown below.Id Gateway
The IdGateway implements
register
andregisterFor
and requires that a storage unit is rented for either. This prevents registration of “empty” fids but users are unaffected since an fid without storage cannot post anything to the network.The IdGateway does not implement
transfer
methods — doing so would compromise decentralization. Even though transfer methods can be spammed, apps can ignore all but the latest transfer event for an fid which makes spam much more manageable.Key Gateway
The KeyGateway implements
add
andaddFor
and limits the number of active keys to 1,000 per user. Users may remove older keys and add new keys once the limit is reached, and an admin can increase this limit in the future.The gateway does not implement
remove
andremoveFor
methods. While it is possible to spam adding and removing keys, apps can ignore all but the latest event, which simplified this issue.Freezing Gateways
Gateways can be frozen to prevent any further changes. This may be necessary if we want to ossify the rules around registration, preventing even admins from changing them again. Freezing is a one-way operation that cannot be undone.
Guardians
Pausable contracts use a “pause guardian” pattern that allows one or more “guardian” addresses to pause, but not unpause contracts. This enables us to further decentralize ownership of the core registry contracts, for example to a higher-threshold multisig, while allowing a set of trusted operators to react quickly and pause contracts in the event of an emergency.
Lookup Methods
The number of events will grow over time and become time consuming to sync. We propose adding lookups for common state by storing it in a mapping in each registry. This increases gas costs but makes it possible to determine state without iterating through historical events.
IdRegistry
Allow looking up the custody address for a given fid.
KeyRegistry
Allow looking up added and removed keys for an fid.
Disclosure
This disclosure will be circulated privately to known app developers in the ecosystem, and shared publicly only 24 hours before the migration. All fids previously registered will be considered valid, since they were in accordance with the rules of the contract. But any fids registered maliciously after this disclosure is published will be considered in violation and will not be migrated to the new contract. The list of skipped fids (if any) and rationale will be added to this proposal.
Rationale
Is this change absolutely necessary?
We could just leave it to all app developers to handle the parsing of dead events, but believe that fixing it today is important because it significantly improves the developer experience.
Why was this not announced publicly earlier?
A malicious actor who discovered the issue via public disclosure could start spamming the contract, causing further pain for app developers and increase the costs and complexity of migrating the contracts.
Release
The contracts will be deployed to the following address:
These are best effort and there’s a good chance that it may be possible sooner or later. Please be prepared for delays up to 48 hours in case issues are run into during migration.
Appendix A: Developer Migration Guide
Contracts
The IdRegistry and KeyRegistry contracts are redeployed and all events emitted will be semantically identical to the old contracts. However, the actual timestamps and transaction ids that created the events will be different. In addition to this, interfaces have changed:
Managing Fids
register
,registerFor
→ IdGatewayregister
,registerFor
Register
signatures must use the newKeyGateway
domain separator.extraStorage
param to rent more than one unit.IdRegistry
.changeRecoveryAddress
— signature hash has changed to include both previous and new recovery address.Renting Storage
Adding Keys
add
,addFor
→ KeyGatewayadd
,addFor
Add
signatures must use the newKeyGateway
domain separator.Bundler
register
now accepts anextraStorage
param which asks for the number of additional units you want to rent beyond 1. Previously this was the total number of units.price
now accepts anextraStorage
param.Hubs
If you are using the latest Hubble, no change should be necessary.
The hub will cut over to the new version of the contracts automatically when the global network config is changed. At this point, hubs will start ingesting all historical events from the new contracts and emitting them as events.
Replicator
If you are using the latest replicator, no change should be necessary.
The new onchain contract events for IdRegistry and KeyRegistry emitted by hubs will be inserted into the
chainEvents
table. All foreign keys will be updated to point to these new events instead of the older ones. The older entries will not be automatically removed, though they are safe to remove after you’ve verified that everything is working as expected.Signatures
Any unused off-chain signatures will be invalid, and need to be regenerated. Code generating typed signatures will need to be updated to use domain separators for the new contracts.
Beta Was this translation helpful? Give feedback.
All reactions