Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonding manager MVP #316

Merged
merged 29 commits into from
Dec 1, 2022
Merged

Bonding manager MVP #316

merged 29 commits into from
Dec 1, 2022

Conversation

ChiTimesChi
Copy link
Collaborator

@ChiTimesChi ChiTimesChi commented Oct 31, 2022

Description

MVP for Bonding Manager: a contract, that is supposed to keep track of all bonded actors.

BondingManager will have two types of deployments:

  1. BondingPrimary: to be deployed on Synapse Chain. This is where Notaries and Guards are supposed to stake/unstake their bonds. Open question: merge with AttestationCollector?
  2. BondingSecondary: to be deployed on chains other than Synapse Chain. Keeps track of active Notaries and Guards, relevant to the chain where the contract is deployed. Doesn't keep track of any agents, but rather enables communication between local contracts and BondingPrimary to keep them in sync.

Changes

  • NotaryManager is deprecated.
  • New contract: BondingManager. The parent contract for BondingPrimary and BondingSecondary: everything they have in common.
  • New contract: BondingPrimary. To be deployed on Synapse Chain, agents are staking and unstaking their bonds there, the information is then passed to BondingSecondary on other chains (actual forwarding of data is out of scope of this PR).
  • New contract: BondingSecondary. To be deployed on chains other than Synapse Chain. Forwards updates about agents between BondingPrimary and system registries (system contracts tracking the agents).
  • New contract: SystemRegistry. It keeps track of the required agents (guards/notaries), which are added or removed by receiving a system call from a local BondingManager.
  • New struct: AgentInfo. Allows to unify bond/unbond Guard/Notary into a single function syncAgents.
    enum Agent {
    Notary,
    Guard
    }
    /**
    * @notice Unified struct for off-chain agent storing
    * @param agent Type of agent: Notary, Guard
    * @param bonded Whether agent bonded or unbonded
    * @param domain Domain, where agent is active (0 means agent is active everywhere)
    * @param account Off-chain agent address
    */
    struct AgentInfo {
    Agent agent;
    bool bonded;
    uint32 domain;
    address account;
    // TODO: 48 bits remaining
    }
  • New system call function: slashAgent. To be used for forwarding information, that an agent has been slashed.
    /**
    * @notice Receive a system call indicating the off-chain agent needs to be slashed.
    * @param _rootSubmittedAt Time when merkle root (used for proving this message) was submitted
    * @param _callOrigin Domain where the system call originated
    * @param _caller Entity which performed the system call
    * @param _info Information about agent to slash
    */
    function slashAgent(
    uint256 _rootSubmittedAt,
    uint32 _callOrigin,
    ISystemRouter.SystemEntity _caller,
    AgentInfo memory _info
    ) external virtual;
  • New system call function: syncAgents. To be used for forwarding information about agents staking/unstaking their bond.
    /**
    * @notice Receive a system call indicating the list of off-chain agents needs to be synced.
    * @param _rootSubmittedAt Time when merkle root (used for proving this message) was submitted
    * @param _callOrigin Domain where the system call originated
    * @param _caller Entity which performed the system call
    * @param _requestID Unique ID of the sync request
    * @param _removeExisting Whether the existing agents need to be removed first
    * @param _infos Information about a list of agents to sync
    */
    function syncAgents(
    uint256 _rootSubmittedAt,
    uint32 _callOrigin,
    ISystemRouter.SystemEntity _caller,
    uint256 _requestID,
    bool _removeExisting,
    AgentInfo[] memory _infos
    ) external virtual;
  • More documentation, tests.

Actors workflow

Bonding

  1. Off-chain actor stakes their bond on BondingPrimary (in the MVP version there would be no actual token staking involved for simplicity, just a record in storage).
  2. BondingPrimary forwards this information to BondingSecondary on other chains (ping).
  3. BondingSecondary informs local system contracts (Origin, Destination) that a new actor is active (eventually, with some kind of delay).
  4. BondingSecondary informs BondingPrimary that new actor was added successfully (pong).
  5. Once all pongs are received by BondingPrimary, the actor is considered active.

Unbonding

  1. Off-chain actor requests the unstaking of their bond on BondingPrimary.
  2. BondingPrimary forwards this information to BondingSecondary on other chains (ping).
  3. BondingSecondary informs local system contracts (Origin, Destination) that the actor is no longer active.
  4. BondingSecondary informs BondingPrimary that new actor was removed successfully (pong).
  5. Once all pongs are received by BondingPrimary, actor is removed everywhere, and their bond is available for unstaking (eventually, with some kind of delay to make sure the unstaking actor could be reported for fraud in time).

Slashing

  1. Any actor could be slashed on Origin by presenting a verifiable proof of their fraud.
  2. Origin informs a local BondingSecondary that the actor has been slashed.
  3. BondingSecondary notifies the remaining local contracts about the slashed actor.
  4. BondingSecondary notifies BondingPrimary about the slashed actor (this step is skipped if actor is slashed on SynChain).
  5. BondingPrimary marks actor's bond as slashed, and notifies BondingSecondary on the remaining chains about the slashed actors.
  6. These BondingSecondary contracts notify local system contract about the slashed actor.

Metadata

@ChiTimesChi ChiTimesChi marked this pull request as draft October 31, 2022 23:38
@github-actions github-actions bot added 2-reviewers C-Protocol-Critical PRs that modify protocol-critical code. M-contracts Module: Contracts labels Oct 31, 2022
@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Base: 33.69382% // Head: 33.81478% // Increases project coverage by +0.12096% 🎉

Coverage data is based on head (c004fbb) compared to base (46e9564).
Patch coverage: 49.65986% of modified lines in pull request are covered.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master        #316         +/-   ##
===================================================
+ Coverage   33.69382%   33.81478%   +0.12095%     
===================================================
  Files            418         423          +5     
  Lines          42073       42026         -47     
  Branches         158         174         +16     
===================================================
+ Hits           14176       14211         +35     
+ Misses         26128       26046         -82     
  Partials        1769        1769                 
Impacted Files Coverage Δ
agents/contracts/origin/mocks/i_origin.go 0.00000% <0.00000%> (ø)
agents/testutil/contracttype.go 81.81818% <ø> (-0.79053%) ⬇️
agents/testutil/typecast.go 100.00000% <ø> (ø)
packages/contracts-core/contracts/Destination.sol 96.66667% <ø> (ø)
packages/contracts-core/contracts/Origin.sol 94.73684% <0.00000%> (-5.26316%) ⬇️
...s/contracts-core/contracts/hubs/DestinationHub.sol 95.65217% <ø> (ø)
...ckages/contracts-core/contracts/hubs/OriginHub.sol 88.88889% <ø> (ø)
.../test/harnesses/system/SystemContractHarness.t.sol 25.00000% <ø> (+1.47059%) ⬆️
...s-core/test/tools/system/SystemContractTools.t.sol 0.00000% <0.00000%> (ø)
...cts-core/test/tools/system/SystemRouterTools.t.sol 0.00000% <0.00000%> (ø)
... and 25 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ChiTimesChi
Copy link
Collaborator Author

Left to do:

  • Tests
  • Ping-pong handling for adding/removing an agent (to be done in a dedicated PR)

Good for review otherwise.

@ChiTimesChi ChiTimesChi marked this pull request as ready for review November 4, 2022 01:06
@ChiTimesChi ChiTimesChi changed the title [WIP] Bonding manager MVP [Pending: tests] Bonding manager MVP Nov 4, 2022
@ChiTimesChi
Copy link
Collaborator Author

Will reopen once a proper mvp for syncing between BondingPrimary and BondingSecondary is implemented

@github-actions github-actions bot temporarily deployed to Preview November 25, 2022 15:47 Inactive
@ChiTimesChi ChiTimesChi removed the Stale label Nov 25, 2022
@ChiTimesChi
Copy link
Collaborator Author

Updated the PR description. The solidity part of the PR should be finished, awaiting the Go changes.

@ChiTimesChi ChiTimesChi changed the title [Pending: tests] Bonding manager MVP [Pending: Go] Bonding manager MVP Nov 25, 2022
@ChiTimesChi ChiTimesChi marked this pull request as ready for review November 25, 2022 17:02
@github-actions github-actions bot temporarily deployed to Preview November 25, 2022 19:05 Inactive
@ChiTimesChi
Copy link
Collaborator Author

ChiTimesChi commented Nov 26, 2022

For the time being, the BondingManager tests feature mocks for Origin, Destination instead of the actual contracts. The full end-to-end test is supposed to be added once #326 is completed.

@github-actions github-actions bot added the go Pull requests that update Go code label Nov 29, 2022
@github-actions github-actions bot temporarily deployed to Preview November 29, 2022 03:59 Inactive
@github-actions github-actions bot temporarily deployed to Preview November 29, 2022 04:38 Inactive
@github-actions github-actions bot temporarily deployed to Preview November 30, 2022 02:25 Inactive
@github-actions github-actions bot temporarily deployed to Preview November 30, 2022 22:54 Inactive
@github-actions
Copy link

This pull request has been deployed to Vercel.

Latest commit: c004fbb
✅ Preview: https://sanguine-b3xrcb4ui-synapsecns.vercel.app
🔍 Inspect: https://vercel.com/synapsecns/sanguine/5pb5GhdY7WfQHwcrSr586uzjxUBo

View Workflow Logs

Copy link
Contributor

@joecroninallen joecroninallen left a comment

Choose a reason for hiding this comment

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

Looks ready to me.

@ChiTimesChi ChiTimesChi merged commit 1e3dcb4 into master Dec 1, 2022
@ChiTimesChi ChiTimesChi deleted the feat/bonding-manager-mvp branch December 1, 2022 14:29
@ChiTimesChi ChiTimesChi changed the title [Pending: Go] Bonding manager MVP Bonding manager MVP Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2-reviewers C-Protocol-Critical PRs that modify protocol-critical code. deployed go Pull requests that update Go code M-contracts Module: Contracts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants