AgentManager

Git Source

Inherits: MessagingBase, AgentManagerEvents, IAgentManager

AgentManager is used to keep track of all the bonded agents and their statuses. The exact logic of how the agent statuses are stored and updated is implemented in child contracts, and depends on whether the contract is used on Synapse Chain or on other chains. AgentManager is responsible for the following:

  • Keeping track of all the bonded agents and their statuses.
  • Keeping track of all the disputes between agents.
  • Notifying AgentSecured contracts about the opened and resolved disputes.
  • Notifying AgentSecured contracts about the slashed agents.

State Variables

origin

address public origin;

destination

address public destination;

inbox

address public inbox;

_agentDispute

mapping(uint256 => AgentDispute) internal _agentDispute;

_disputes

OpenedDispute[] internal _disputes;

__GAP

gap for upgrade safety

uint256[45] private __GAP;

Functions

onlyInbox

modifier onlyInbox();

onlyWhenStuck

modifier onlyWhenStuck();

__AgentManager_init

function __AgentManager_init(address origin_, address destination_, address inbox_) internal onlyInitializing;

openDispute

Allows Inbox to open a Dispute between a Guard and a Notary, if they are both not in Dispute already.

Will revert if any of these is true:

  • Caller is not Inbox.
  • Guard or Notary is already in Dispute.
function openDispute(uint32 guardIndex, uint32 notaryIndex) external onlyInbox;

Parameters

NameTypeDescription
guardIndexuint32Index of the Guard in the Agent Merkle Tree
notaryIndexuint32Index of the Notary in the Agent Merkle Tree

slashAgent

Allows Inbox to slash an agent, if their fraud was proven.

Will revert if any of these is true:

  • Caller is not Inbox.
  • Domain doesn't match the saved agent domain.
function slashAgent(uint32 domain, address agent, address prover) external onlyInbox;

Parameters

NameTypeDescription
domainuint32Domain where the Agent is active
agentaddressAddress of the Agent
proveraddressAddress that initially provided fraud proof

getAgent

Returns agent address and their current status for a given agent index.

Will return empty values if agent with given index doesn't exist.

function getAgent(uint256 index) external view returns (address agent, AgentStatus memory status);

Parameters

NameTypeDescription
indexuint256Agent index in the Agent Merkle Tree

Returns

NameTypeDescription
agentaddressAgent address
statusAgentStatusStatus for the given agent: (flag, domain, index)

agentStatus

Returns (flag, domain, index) for a given agent. See Structures.sol for details.

Will return AgentFlag.Fraudulent for agents that have been proven to commit fraud, but their status is not updated to Slashed yet.

function agentStatus(address agent) public view returns (AgentStatus memory status);

Parameters

NameTypeDescription
agentaddressAgent address

Returns

NameTypeDescription
statusAgentStatusStatus for the given agent: (flag, domain, index).

getDisputesAmount

Returns the number of opened Disputes.

This includes the Disputes that have been resolved already.

function getDisputesAmount() external view returns (uint256);

getDispute

Returns information about the dispute with the given index.

Will revert if dispute with given index hasn't been opened yet.

function getDispute(uint256 index)
    external
    view
    returns (
        address guard,
        address notary,
        address slashedAgent,
        address fraudProver,
        bytes memory reportPayload,
        bytes memory reportSignature
    );

Parameters

NameTypeDescription
indexuint256Dispute index

Returns

NameTypeDescription
guardaddressAddress of the Guard in the Dispute
notaryaddressAddress of the Notary in the Dispute
slashedAgentaddressAddress of the Agent who was slashed when Dispute was resolved
fraudProveraddressAddress who provided fraud proof to resolve the Dispute
reportPayloadbytesRaw payload with report data that led to the Dispute
reportSignaturebytesGuard signature for the report payload

disputeStatus

Returns the current Dispute status of a given agent. See Structures.sol for details.

Every returned value will be set to zero if agent was not slashed and is not in Dispute. rival and disputePtr will be set to zero if the agent was slashed without being in Dispute.

function disputeStatus(address agent)
    external
    view
    returns (DisputeFlag flag, address rival, address fraudProver, uint256 disputePtr);

Parameters

NameTypeDescription
agentaddressAgent address

Returns

NameTypeDescription
flagDisputeFlagFlag describing the current Dispute status for the agent: None/Pending/Slashed
rivaladdressAddress of the rival agent in the Dispute
fraudProveraddressAddress who provided fraud proof to resolve the Dispute
disputePtruint256Index of the opened Dispute PLUS ONE. Zero if agent is not in Dispute.

_afterAgentSlashed

Hook that is called after agent was slashed in AgentManager and AgentSecured contracts were notified.

function _afterAgentSlashed(uint32 domain, address agent, address prover) internal virtual;

_notifyDisputeOpened

Child contract should implement the logic for notifying AgentSecured contracts about the opened dispute.

function _notifyDisputeOpened(uint32 guardIndex, uint32 notaryIndex) internal virtual;

_notifyDisputeResolved

Child contract should implement the logic for notifying AgentSecured contracts about the resolved dispute.

function _notifyDisputeResolved(uint32 slashedIndex, uint32 rivalIndex) internal virtual;

_slashAgent

Slashes the Agent and notifies the local Destination and Origin contracts about the slashed agent. Should be called when the agent fraud was confirmed.

function _slashAgent(uint32 domain, address agent, address prover) internal;

_resolveDispute

Resolves a Dispute between a slashed Agent and their Rival (if there was one).

function _resolveDispute(uint32 slashedIndex, address prover) internal;

_agentLeaf

Generates leaf to be saved in the Agent Merkle Tree

function _agentLeaf(AgentFlag flag, uint32 domain, address agent) internal pure returns (bytes32);

_storedAgentStatus

Returns the last known status for the agent from the Agent Merkle Tree. Note: the actual agent status (returned by agentStatus()) may differ, if agent fraud was proven.

function _storedAgentStatus(address agent) internal view virtual returns (AgentStatus memory);

_getAgent

Returns agent address for the given index. Returns zero for non existing indexes.

function _getAgent(uint256 index) internal view virtual returns (address);

_getIndex

Returns the index of the agent in the Agent Merkle Tree. Returns zero for non existing agents.

function _getIndex(address agent) internal view virtual returns (uint256);

Structs

AgentDispute

struct AgentDispute {
    DisputeFlag flag;
    uint88 disputePtr;
    address fraudProver;
}

OpenedDispute

struct OpenedDispute {
    uint32 guardIndex;
    uint32 notaryIndex;
    uint32 slashedIndex;
}