Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Feature/collective key broadcast #17

Merged
merged 8 commits into from
Apr 5, 2024

Conversation

konradkonrad
Copy link
Contributor

@konradkonrad konradkonrad commented Jan 31, 2024

This adds a new contract and contract role to the Keyper contracts:

The contract EonKeyPublish is the entrypoint for keypers to announce a
new Eon key. The contract tracks that the configured threshold of
keypers agreed on the same eon key, and only then forwards it to the
KeyBroadcastContract. The existing logic was changed, so that only a
contract, that implements the interface EonKeyPublisher, is allowed to
call the broadcasting contract. A publisher must be set for each
KeyperSet before it gets finalized.

The role of the broadcaster was changed to publisher, to reflect that calling EonKeyPublisher is only part of a (threshold controlled) collective action that will only in the successful case (threshold achieved) result in a "broadcast".

After the latest rework, this is still missing a few things:

  • tests for the confirmation logic
  • test for the newly introduced event EonVoteRegistered
  • change how we deal with eon votes after the threshold was reached and the broadcast event was emitted (should not fail)

@konradkonrad konradkonrad force-pushed the feature/collective-key-broadcast branch 2 times, most recently from b52e134 to c60d843 Compare January 31, 2024 13:31
src/KeyperSet.sol Show resolved Hide resolved
src/EonKeyPublish.sol Show resolved Hide resolved
src/KeyperSet.sol Outdated Show resolved Hide resolved
src/KeyperSet.sol Outdated Show resolved Hide resolved
This adds a new contract and contract role to the Keyper contracts:

The contract `EonKeyPublish` is the entrypoint for keypers to announce a
new Eon key. The contract tracks that the configured threshold of
keypers agreed on the same eon key, and only then forwards it to the
`KeyBroadcastContract`. The existing logic was changed, so that only a
contract, that implements the interface `EonKeyPublisher`, is allowed to
call the broadcasting contract. A publisher must be set for each
`KeyperSet` before it gets finalized.
@konradkonrad konradkonrad force-pushed the feature/collective-key-broadcast branch from c60d843 to dff2b70 Compare February 1, 2024 09:41
This incorporates most of the PR feedback from https://github.com/shutter-network/shop-contracts/pull/17/files

- Renamed the `broadcaster` role to `publisher`
- Get rid of `getKeyperIndex` method
- Simplify counting logic in `EonKeyPublish.sol`
@konradkonrad konradkonrad force-pushed the feature/collective-key-broadcast branch from 73809bd to f3e0c27 Compare February 1, 2024 12:24
@konradkonrad konradkonrad marked this pull request as draft February 1, 2024 12:26
If an eonkey is already above the confirmation threshold, there should be no
failure. We now instead emit an event that let's the caller know, that the
eon key was already broadcast.
@konradkonrad konradkonrad marked this pull request as ready for review February 5, 2024 11:13
Copy link
Contributor

@jannikluhn jannikluhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM except for two small things that should be easy to fix. But I'm also fine to merge it as is and fix it in a follow up PR.

!KeyperSet(keyperSetManager.getKeyperSetAddress(eon))
.isAllowedToBroadcastEonKey(msg.sender)
) {
if (!EonKeyPublisher(keyperSet.getPublisher()).eonKeyConfirmed(key)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change means the key broadcaster only works with the publisher contract, but for testing we'll still often want to use an EOA for instance. It also doesn't seem necessary since it's already checked in the publisher. So I think this should be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://github.com/shutter-network/shop-contracts/pull/17/files#diff-3d3a21aeab5a8ee50b2a9156a6d68881191ec03ebee386493b1299fa2646c92fR9-R13 for how I envisoned that use case. A bit cumbersome, but works for the testing use case. Removing this would allow a keyper to call broadcast directly, I believe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this would allow a keyper to call broadcast directly, I believe.

there's still the !keyperSet.isAllowedToBroadcastEonKey(msg.sender) check for access control, no?

@@ -23,12 +27,16 @@ contract KeyBroadcastContract {
revert InvalidKey();
}
if (keys[eon].length > 0) {
revert AlreadyHaveKey();
emit AlreadyHaveKey(eon, key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reverting is preferable here. One reason is that the caller won't know about the event, so they'll assume the key has been broadcast. This is misleading, especially if the new key would be different from the old one. Reverting gives the caller the option to either let the error propagate or to catch it.

So I think we should revert with AlreadyHaveKey here as before and handle the error in a try-catch block in EonKeyPublish.publishEonKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about solidity try-catch

Copy link
Contributor

@jannikluhn jannikluhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jannikluhn jannikluhn merged commit 493c078 into main Apr 5, 2024
2 checks passed
@jannikluhn jannikluhn deleted the feature/collective-key-broadcast branch April 5, 2024 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants