thehubbleproject / hubble-contracts

Hubble optimistic rollup
https://thehubbleproject.github.io/docs/
MIT License
133 stars 28 forks source link

Sync public key registration #553

Closed ChihChengLiang closed 3 years ago

ChihChengLiang commented 3 years ago

What's wrong

The syncer now only learns only new batch events on-chain, we need to sync new public key registration too. So that the client can validate the signature signed by the latest added keys.

How can we fix it

Add method to parse public event in the initialSync function in the SyncerService.

It would be similar to how we parse batches.

https://github.com/thehubbleproject/hubble-contracts/blob/42b6f3676dd9dda8ac601dae0137a1c4da87c1ba/ts/client/services/syncer.ts#L42-L55

There are two ways to register public keys. One is to register a single public key and the other is to register many public keys at once.

They emit SinglePubkeyRegistered and BatchPubkeyRegistered respectively.

Note that in those events you can't get the actual public key. You can get only the public key ID. To get the actual public key we need to parse calldata like what we did in parsing the batch.

To keep the task size small, we could implement only the SinglePubkeyRegistered and log an error for the BatchPubkeyRegistered. We can implement BatchPubkeyRegistered later in the next issue.

ChihChengLiang commented 3 years ago

Note that we use storageManagerFactory to add preconfigured public keys to the offchain pubkeyStorage in the integration test and in the real node. That was for convenience reason so we can have public keys offchain without syncing from the contract.

But that also causes the off-chain data inconsistent with the on-chain public key contract (blsAccountRegistry).

Once public key sync is implemented, we need to

  1. Remove the adding public key part in storageManagerFactory.
  2. Add the preconfigured public keys to the blsAccountRegistry in the deployment script.