Skip to content

Commit

Permalink
Merge pull request #39 from gnosis/ref/ownable
Browse files Browse the repository at this point in the history
ref: refactor ShuSo, ShoyuBashi and GiriGiriBashi & fix _getThresholdHash
  • Loading branch information
allemanfredi authored Jan 30, 2024
2 parents 74fb30b + eb65993 commit 8acfa29
Show file tree
Hide file tree
Showing 12 changed files with 543 additions and 373 deletions.
192 changes: 192 additions & 0 deletions packages/evm/contracts/interfaces/IGiriGiriBashi.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { IHashi } from "./IHashi.sol";
import { IOracleAdapter } from "./IOracleAdapter.sol";
import { IShuSho } from "./IShuSho.sol";

/**
* @title IGiriGiriBashi
*/
interface IGiriGiriBashi is IShuSho {
struct Settings {
bool quarantined; // whether or not the adapter has has been quarantined.
uint256 minimumBond; // amount that must be bonded alongside a challenge.
uint256 startId; // earliest id that the oracle could have reported.
uint256 idDepth; // how far behind the current head can this oracle safely report. 0 equals infinite.
uint256 timeout; // grace period in which the oracle must report on an in range id after being challenged.
}

struct Challenge {
address payable challenger; // account that raised the challenge.
uint256 timestamp; // timestamp when the challenge was created.
uint256 bond; // bond paid by the challenger.
}

event BondRecipientSet(address payable bondRecipient);
event NewHead(uint256 domain, uint256 head);
event ChallegenRangeUpdated(uint256 domain, uint256 range);
event SettingsInitialized(uint256 domain, IOracleAdapter adapter, Settings settings);
event ChallengeCreated(
bytes32 challengeId,
uint256 indexed domain,
uint256 id,
IOracleAdapter indexed adapter,
address indexed challenger,
uint256 timestamp,
uint256 bond
);
event ChallengeResolved(
bytes32 challengeId,
uint256 indexed domain,
uint256 id,
IOracleAdapter indexed adapter,
address indexed challenger,
uint256 bond,
bool challengeSuccessful
);
event NoConfidenceDeclareed(uint256 domain);

error DuplicateChallenge(bytes32 challengeId, uint256 domain, uint256 id, IOracleAdapter adapter);
error OutOfRange(IOracleAdapter adapter, uint256 id);
error AlreadyQuarantined(IOracleAdapter adapter);
error NotEnoughtValue(IOracleAdapter adapter, uint256 value);
error ChallengeNotFound(bytes32 challengeId, uint256 domain, uint256 id, IOracleAdapter adapter);
error AdapterHasNotYetTimedOut(IOracleAdapter adapter);
error UnequalArrayLengths();
error AdapterNotQuarantined(IOracleAdapter adapter);
error CannotProveNoConfidence(uint256 domain, uint256 id, IOracleAdapter[] adapters);
error AdaptersAgreed(IOracleAdapter, IOracleAdapter);
error NoConfidenceRequired();
error CountMustBeZero(uint256 domain);
error ChallengeRangeAlreadySet(uint256 domain);

/**
* @dev Sets the threshold for a specific domain.
* @param domain - The Uint256 identifier for the domain.
* @param threshold - The Uint256 threshold to set for the given domain.
*/
function setThreshold(uint256 domain, uint256 threshold) external;

/**
* @dev Sets the bond recipient address for payments.
* @param bondRecipient - The address where bond payments should be sent.
*/
function setBondRecipient(address payable bondRecipient) external;

/**
* @dev Sets the challenge range for a specific domain.
* @param domain - The Uint256 identifier for the domain.
* @param range - The Uint256 range to set for the given domain.
*/
function setChallengeRange(uint256 domain, uint256 range) external;

/**
* @dev Challenges the oracle adapter to provide a response. If the oracle adapter fails, it can be quarantined.
* @param domain - The Uint256 identifier for the domain.
* @param id - The Uint256 identifier for the challenge.
* @param adapter - The address of the oracle adapter to challenge.
* @notice Caller must pay a minimum bond to issue the challenge. This bond should be high enough to cover the gas costs for successfully completing the challenge.
*/
function challengeOracleAdapter(uint256 domain, uint256 id, IOracleAdapter adapter) external payable;

/**
* @dev Resolves a challenge by comparing results from a specific oracle adapter with others.
* @param domain - The Uint256 identifier for the domain.
* @param id - The Uint256 identifier.
* @param adapter - The oracle adapter instance for comparison.
* @param adapters - An array of oracle adapter instances for comparison.
* @return A boolean indicating the success of the challenge resolution.
*/
function resolveChallenge(
uint256 domain,
uint256 id,
IOracleAdapter adapter,
IOracleAdapter[] memory adapters
) external returns (bool);

/**
* @dev show that enough oracles disagree that they could not make a threshold if the remainder all agree with one.
* @param domain - The Uint256 identifier for the domain.
* @param id - The Uint256 identifier.
* @param adapters - An array of oracle adapter instances.
*/
function declareNoConfidence(uint256 domain, uint256 id, IOracleAdapter[] memory adapters) external;

/**
* @dev Replaces the quarantined oracle adapters for a given domain with new adapters and settings.
* @param domain - The Uint256 identifier for the domain.
* @param currentAdapters - An array of current oracle adapter instances to be replaced.
* @param newAdapters - An array of new oracle adapter instances to replace the current ones.
* @param settings - An array of settings corresponding to the new adapters.
*/
function replaceQuaratinedOrcales(
uint256 domain,
IOracleAdapter[] memory currentAdapters,
IOracleAdapter[] memory newAdapters,
Settings[] memory settings
) external;

/**
* @dev Disables a set of oracle adapters for a given domain.
* @param domain - The Uint256 identifier for the domain.
* @param adapters - An array of oracle adapter instances to be disabled.
*/
function disableOracleAdapters(uint256 domain, IOracleAdapter[] memory adapters) external;

/**
* @dev Enables a set of oracle adapters for a given domain with specific settings.
* @param domain - The Uint256 identifier for the domain.
* @param adapters - An array of oracle adapter instances.
* @param settings - An array of settings, corresponding to each adapter.
*/
function enableOracleAdapters(
uint256 domain,
IOracleAdapter[] memory adapters,
Settings[] memory settings
) external;

/**
* @dev Gets the challenge ID for a given domain, ID, and oracle adapter.
* @param domain - The Uint256 identifier for the domain.
* @param id - The Uint256 identifier.
* @param adapter - The oracle adapter instance.
* @return The computed challenge ID as a bytes32 hash.
*/
function getChallengeId(uint256 domain, uint256 id, IOracleAdapter adapter) external pure returns (bytes32);

/**
* @dev Returns the hash unanimously agreed upon by ALL of the enabled oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param id - Uint256 identifier to query.
* @return hash - Bytes32 hash agreed upon by the oracles for the given domain.
* @notice Reverts if oracles disagree.
* @notice Reverts if oracles have not yet reported the hash for the given ID.
* @notice Reverts if no oracles are set for the given domain.
*/
function getUnanimousHash(uint256 domain, uint256 id) external returns (bytes32 hash);

/**
* @dev Returns the hash agreed upon by a threshold of the enabled oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param id - Uint256 identifier to query.
* @return hash - Bytes32 hash agreed upon by a threshold of the oracles for the given domain.
* @notice Reverts if no threshold is not reached.
* @notice Reverts if no oracles are set for the given domain.
*/
function getThresholdHash(uint256 domain, uint256 id) external returns (bytes32 hash);

/**
* @dev Returns the hash unanimously agreed upon by all of the given oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param adapters - Array of oracle adapter addresses to query.
* @param id - Uint256 identifier to query.
* @return hash - Bytes32 hash agreed upon by the oracles for the given domain.
* @notice adapters must be in numerical order from smallest to largest and contain no duplicates.
* @notice Reverts if adapters are out of order or contain duplicates.
* @notice Reverts if oracles disagree.
* @notice Reverts if oracles have not yet reported the hash for the given ID.
* @notice Reverts if no oracles are set for the given domain.
*/
function getHash(uint256 domain, uint256 id, IOracleAdapter[] memory adapters) external returns (bytes32 hash);
}
1 change: 1 addition & 0 deletions packages/evm/contracts/interfaces/IHashi.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IHashi {
* @param id - ID for which to return hash.
* @param threshold - Threshold to use.
* @param oracleAdapters - Array of addresses for the oracle adapters to query.
* @notice If the threshold is 1, it will always return true.
* @return result A boolean indicating if a threshold for a given message has been reached.
*/
function checkHashWithThresholdFromOracles(
Expand Down
9 changes: 8 additions & 1 deletion packages/evm/contracts/interfaces/IHeaderStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ pragma solidity ^0.8.17;
* @title IHeaderStorage
*/
interface IHeaderStorage {
error HeaderOutOfRange(address emitter, uint256 blockNumber);
error HeaderOutOfRange(uint256 blockNumber);

event HeaderStored(uint256 indexed blockNumber, bytes32 indexed blockHeader);

/**
* @dev Retrieves the stored block header for a specific block number.
* @param blockNumber - The block number as a uint256 value.
* @return The block header as a bytes32 value.
*/
function headers(uint256 blockNumber) external view returns (bytes32);

/**
* @dev Stores and returns the header for the given block.
* @param blockNumber - Block number.
Expand Down
73 changes: 73 additions & 0 deletions packages/evm/contracts/interfaces/IShoyuBashi.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { IHashi } from "./IHashi.sol";
import { IOracleAdapter } from "./IOracleAdapter.sol";
import { IShuSho } from "./IShuSho.sol";

/**
* @title IShoyuBashi
*/
interface IShoyuBashi is IShuSho {
/**
* @dev Sets the threshold of adapters required for a given domain.
* @param domain - Uint256 identifier for the domain for which to set the threshold.
* @param threshold - Uint256 threshold to set for the given domain.
* @notice Only callable by the owner of this contract.
* @notice Reverts if the threshold is already set to the given value.
*/
function setThreshold(uint256 domain, uint256 threshold) external;

/**
* @dev Enables the given adapters for a given domain.
* @param domain - Uint256 identifier for the domain for which to set oracle adapters.
* @param adapters - Array of oracleAdapter addresses.
* @notice Reverts if adapters are out of order or contain duplicates.
* @notice Only callable by the owner of this contract.
*/
function enableOracleAdapters(uint256 domain, IOracleAdapter[] memory adapters) external;

/**
* @dev Disables the given adapters for a given domain.
* @param domain - Uint256 identifier for the domain for which to set oracle adapters.
* @param adapters - Array of oracleAdapter addresses.
* @notice Reverts if adapters are out of order or contain duplicates.
* @notice Only callable by the owner of this contract.
*/
function disableOracleAdapters(uint256 domain, IOracleAdapter[] memory adapters) external;

/**
* @dev Returns the hash unanimously agreed upon by ALL of the enabled oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param id - Uint256 identifier to query.
* @return Bytes32 hash agreed upon by the oracles for the given domain.
* @notice Reverts if oracles disagree.
* @notice Reverts if oracles have not yet reported the hash for the given ID.
* @notice Reverts if no oracles are set for the given domain.
*/
function getUnanimousHash(uint256 domain, uint256 id) external view returns (bytes32);

/**
* @dev Returns the hash agreed upon by a threshold of the enabled oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param id - Uint256 identifier to query.
* @return Bytes32 hash agreed upon by a threshold of the oracles for the given domain.
* @notice Reverts if the threshold is not reached.
* @notice Reverts if no oracles are set for the given domain.
*/
function getThresholdHash(uint256 domain, uint256 id) external view returns (bytes32);

/**
* @dev Returns the hash unanimously agreed upon by all of the given oraclesAdapters.
* @param domain - Uint256 identifier for the domain to query.
* @param adapters - Array of oracle adapter addresses to query.
* @param id - Uint256 identifier to query.
* @return Bytes32 hash agreed upon by the oracles for the given domain.
* @notice adapters must be in numerical order from smallest to largest and contain no duplicates.
* @notice Reverts if adapters are out of order or contain duplicates.
* @notice Reverts if oracles disagree.
* @notice Reverts if oracles have not yet reported the hash for the given ID.
* @notice Reverts if no oracles are set for the given domain.
*/
function getHash(uint256 domain, uint256 id, IOracleAdapter[] memory adapters) external view returns (bytes32);
}
38 changes: 38 additions & 0 deletions packages/evm/contracts/interfaces/IShuSho.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { IHashi } from "./IHashi.sol";
import { IOracleAdapter } from "./IOracleAdapter.sol";

/**
* @title IShuSho
*/
interface IShuSho {
struct Link {
IOracleAdapter previous;
IOracleAdapter next;
}

event HashiSet(IHashi indexed hashi);
event Init(address indexed owner, IHashi indexed hashi);
event OracleAdaptersEnabled(uint256 indexed domain, IOracleAdapter[] adapters);
event OracleAdaptersDisabled(uint256 indexed domain, IOracleAdapter[] adapters);
event ThresholdSet(uint256 domain, uint256 threshold);

error AdapterNotEnabled(IOracleAdapter adapter);
error AdapterAlreadyEnabled(IOracleAdapter adapter);
error DuplicateHashiAddress(IHashi hashi);
error DuplicateOrOutOfOrderAdapters(IOracleAdapter adapterOne, IOracleAdapter adapterTwo);
error DuplicateThreashold(uint256 threshold);
error InvalidAdapter(IOracleAdapter adapter);
error NoAdaptersEnabled(uint256 domain);
error NoAdaptersGiven();
error ThresholdNotMet();

/**
* @dev Checks the order and validity of oracle adapters for a given domain.
* @param domain - The Uint256 identifier for the domain.
* @param _adapters - An array of oracle adapter instances.
*/
function checkAdapterOrderAndValidity(uint256 domain, IOracleAdapter[] memory _adapters) external view;
}
Loading

0 comments on commit 8acfa29

Please sign in to comment.