Skip to content

Commit

Permalink
Merge branch 'dev' into perf/opo-594-bond-escalation-module
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 21, 2023
2 parents 2186a5f + 9eda7b0 commit 3cf4580
Show file tree
Hide file tree
Showing 47 changed files with 4,530 additions and 5,467 deletions.
2 changes: 1 addition & 1 deletion docs/src/content/modules/dispute/bonded_dispute_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Bonded Dispute Module is a contract that allows users to dispute a proposed

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `decodeRequestData(bytes calldata _data)`: Returns the decoded data for a request.
- `disputeResponse(bytes32 _requestId, bytes32 _responseId, address _disputer, address _proposer)`: Starts a dispute.
- `onDisputeStatusChange(bytes32 _disputeId, IOracle.Dispute memory _dispute)`: Is a hook called by the oracle when a dispute status has been updated.
- `disputeEscalated(bytes32 _disputeId)`: Called by the oracle when a dispute has been escalated. Not implemented in this module.
Expand Down
7 changes: 3 additions & 4 deletions docs/src/content/modules/dispute/circuit_resolver_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ The Circuit Resolver Module is a pre-dispute module that allows disputers to ver

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `disputeResponse(bytes32 _requestId, bytes32 _responseId, address _disputer, address _proposer)`: Verifies the ZK circuit and compares it to the proposed one. Updates the dispute status after checking if the disputed response is indeed wrong.
- `onDisputeStatusChange(bytes32 _requestId, IOracle.Dispute memory _dispute)`: Updates the status of the dispute and resolves it by proposing the correct circuit as a response and finalizing the request.
- `disputeEscalated(bytes32 _disputeId)`: This function is present to comply with the module interface but it is not implemented since this is a pre-dispute module.
- `decodeRequestData`: Returns the decoded data for a request.
- `disputeResponse`: Verifies the ZK circuit and compares it to the proposed one. Updates the dispute status after checking if the disputed response is indeed wrong.
- `onDisputeStatusChange`: Updates the status of the dispute and resolves it by proposing the correct circuit as a response and finalizing the request.

### Request Parameters

Expand Down
7 changes: 3 additions & 4 deletions docs/src/content/modules/dispute/root_verification_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ The Root Verification Module is a pre-dispute module that allows disputers to ca

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `disputeResponse(bytes32 _requestId, bytes32 _responseId, address _disputer, address _proposer)`: Calculates the correct root and compares it to the proposed one. Updates the dispute status after checking if the disputed response is indeed wrong.
- `onDisputeStatusChange(bytes32 _requestId, IOracle.Dispute memory _dispute)`: Updates the status of the dispute and resolves it by proposing the correct root as a response and finalizing the request.
- `disputeEscalated(bytes32 _disputeId)`: This function is present to comply with the module interface but it is not implemented since this is a pre-dispute module.
- `decodeRequestData`: Returns the decoded data for a request.
- `disputeResponse`: Calculates the correct root and compares it to the proposed one. Updates the dispute status after checking if the disputed response is indeed wrong.
- `onDisputeStatusChange`: Updates the status of the dispute and resolves it by proposing the correct root as a response and finalizing the request.

### Request Parameters

Expand Down
5 changes: 2 additions & 3 deletions docs/src/content/modules/finality/callback_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The Callback Module is a finality module that allows users to call a function on

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `finalizeRequest(bytes32 _requestId, address)`: Executing the callback call on the target.
- `decodeRequestData`: Returns the decoded data for a request.
- `finalizeRequest`: Executing the callback call on the target.

### Request Parameters

Expand All @@ -25,4 +25,3 @@ As any finality module, the `CallbackModule` implements the `finalizeRequest` fu
## 4. Gotchas

- The success of the callback call in `finalizeRequest` is purposely not checked, specifying a function or parameters that lead to a revert will not stop the request from being finalized.
- The target must be a contract.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `MultipleCallbacksModule` is a finality module that allows users to make mul

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request. The returned data includes the target addresses for the callback and the calldata forwarded to the targets.
- `finalizeRequest(bytes32 _requestId, address)`: Finalizes the request by executing the callback calls on the targets.
- `decodeRequestData`: Returns the decoded data for a request. The returned data includes the target addresses for the callback and the calldata forwarded to the targets.
- `finalizeRequest`: Finalizes the request by executing the callback calls on the targets.

### Request Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `ContractCallRequestModule` is a module for requesting on-chain information.

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This method decodes the request data for a given request ID. It returns the target contract address, the function selector, the encoded arguments of the function to call, the accounting extension to bond and release funds, the payment token, and the payment amount.
- `finalizeRequest(bytes32 _requestId, address)`: This method finalizes a request by paying the response proposer. It is only callable by the oracle.
- `decodeRequestData`: This method decodes the request data for a given request ID. It returns the target contract address, the function selector, the encoded arguments of the function to call, the accounting extension to bond and release funds, the payment token, and the payment amount.
- `finalizeRequest`: This method finalizes a request by paying the response proposer. It is only callable by the oracle.

### Request Parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/src/content/modules/request/http_request_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `HttpRequestModule` is a contract that allows users to request HTTP calls.

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This method decodes the data for a request given its ID. It returns the URL, HTTP method, body, accounting extension, payment token, and payment amount associated with the request.
- `finalizeRequest(bytes32 _requestId, address)`: This method finalizes a request by paying the proposer if there is a valid response, or releases the requester bond if no valid response was provided.
- `decodeRequestData`: This method decodes request parameters. It returns the URL, HTTP method, body, accounting extension, payment token, and payment amount from the given data.
- `finalizeRequest`: This method finalizes a request by paying the proposer if there is a valid response, or releases the requester bond if no valid response was provided.

### Request Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ The `SparseMerkleTreeRequestModule` is a contract that allows a user to request

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: This function decodes the request data for a given request ID. It returns a RequestParameters struct that contains the parameters for the request.
- `finalizeRequest(bytes32 _requestId, address _finalizer)`: This function is called by the Oracle to finalize the request. It either pays the proposer for the response or releases the requester's bond if no response was submitted.
- `decodeRequestData`: This function decodes the request data for a given request ID. It returns a RequestParameters struct that contains the parameters for the request.
- `finalizeRequest`: This function is called by the Oracle to finalize the request. It either pays the proposer for the response or releases the requester's bond if no response was submitted.

### Request Parameters

Expand All @@ -28,5 +28,5 @@ The `SparseMerkleTreeRequestModule` uses a Merkle tree to calculate the root fro

## 4. Gotchas

- The module is supposed to be paired with the root verification module.
- The module is supposed to be paired with [`RootVerificationModule`](../dispute/root_verification_module.md).
- The verifier contract must follow the `ITreeVerifier` interface, otherwise the proposers won't be able to calculate the correct response.
10 changes: 5 additions & 5 deletions docs/src/content/modules/resolution/arbitrator_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The Arbitrator Module is a part of the dispute resolution system. It allows an e

### Key Methods

- `getStatus(bytes32 _disputeId)`: Returns the arbitration status of a dispute.
- `isValid(bytes32 _disputeId)`: Indicates whether the dispute has been arbitrated.
- `startResolution(bytes32 _disputeId)`: Starts the arbitration process by calling `resolve` on the arbitrator and flags the dispute as `Active`.
- `resolveDispute(bytes32 _disputeId)`: Resolves the dispute by getting the answer from the arbitrator and notifying the oracle.
- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `getStatus`: Returns the arbitration status of a dispute.
- `isValid`: Indicates whether the dispute has been arbitrated.
- `startResolution`: Starts the arbitration process by calling `resolve` on the arbitrator and flags the dispute as `Active`.
- `resolveDispute`: Resolves the dispute by getting the answer from the arbitrator and notifying the oracle.
- `decodeRequestData`: Returns the decoded data for a request.

### Request Parameters

Expand Down
10 changes: 5 additions & 5 deletions docs/src/content/modules/resolution/erc20_resolution_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ The `ERC20ResolutionModule` is a dispute resolution module that decides on the o

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Decodes the request data associated with a given request ID.
- `startResolution(bytes32 _disputeId)`: Starts the resolution process for a given dispute.
- `castVote(bytes32 _requestId, bytes32 _disputeId, uint256 _numberOfVotes)`: Allows a user to cast votes for a dispute.
- `resolveDispute(bytes32 _disputeId)`: Resolves a dispute based on the votes cast.
- `getVoters(bytes32 _disputeId)`: Returns the addresses of the voters for a given dispute.
- `decodeRequestData`: Decodes the request data associated with a given request ID.
- `startResolution`: Starts the resolution process for a given dispute.
- `castVote`: Allows a user to cast votes for a dispute.
- `resolveDispute`: Resolves a dispute based on the votes cast.
- `getVoters`: Returns the addresses of the voters for a given dispute.

### Request Parameters

Expand Down
13 changes: 5 additions & 8 deletions docs/src/content/modules/response/bonded_response_module.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ The Bonded Response Module is a contract that allows users to propose a response

### Key Methods

- `decodeRequestData(bytes32 _requestId)`: Returns the decoded data for a request.
- `propose(bytes32 _requestId, address _proposer, bytes calldata _responseData)`: Proposes a response for a request, bonding the proposer's tokens.
- `deleteResponse(bytes32 _requestId, bytes32 _responseId, address _proposer)`: Allows a user to delete an undisputed response they proposed before the deadline, releasing the bond.
- `finalizeRequest(bytes32 _requestId, address _finalizer)`: Finalizes the request.
- `decodeRequestData`: Returns the decoded data for a request.
- `propose`: Proposes a response for a request, bonding the proposer's tokens.
- `finalizeRequest`: Finalizes the request.

### Request Parameters

Expand All @@ -24,14 +23,12 @@ The Bonded Response Module is a contract that allows users to propose a response

## 3. Key Mechanisms & Concepts

- Deleting a response: If a proposer realizes the response they've submitted is incorrect, they can delete it. Note that disputed responses cannot be taken back.

- Early finalization: It is possible for pre-dispute modules to atomically calculate the correct response on-chain, decide on the result of a dispute and finalize the request before its deadline.

- Dispute window: Prevents proposers from submitting a response 1 block before the deadline and finalizing it in the next block, leaving disputers no time to dispute the response.

## 4. Gotchas

- In case of no valid responses, a request can be finalized after the deadline and the requester will get back their tokens.
- A proposer might submit a response 1 block before the deadline and finalize it in the next block, making it impossible to dispute.
- Users cannot propose a response after the deadline for a request.
- Users cannot propose a response if an undisputed response has already been proposed.
- Users cannot delete a response after the proposing deadline.
197 changes: 94 additions & 103 deletions solidity/contracts/modules/dispute/BondedDisputeModule.sol
Original file line number Diff line number Diff line change
@@ -1,115 +1,106 @@
// // SPDX-License-Identifier: MIT
// pragma solidity ^0.8.19;
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

// // solhint-disable-next-line no-unused-import
// import {Module, IModule} from '@defi-wonderland/prophet-core-contracts/solidity/contracts/Module.sol';
// import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol';
// solhint-disable-next-line no-unused-import
import {Module, IModule} from '@defi-wonderland/prophet-core-contracts/solidity/contracts/Module.sol';
import {IOracle} from '@defi-wonderland/prophet-core-contracts/solidity/interfaces/IOracle.sol';

// import {IBondedDisputeModule} from '../../../interfaces/modules/dispute/IBondedDisputeModule.sol';
import {IBondedDisputeModule} from '../../../interfaces/modules/dispute/IBondedDisputeModule.sol';

// contract BondedDisputeModule is Module, IBondedDisputeModule {
// constructor(IOracle _oracle) Module(_oracle) {}
contract BondedDisputeModule is Module, IBondedDisputeModule {
constructor(IOracle _oracle) Module(_oracle) {}

// /// @inheritdoc IModule
// function moduleName() external pure returns (string memory _moduleName) {
// return 'BondedDisputeModule';
// }
/// @inheritdoc IModule
function moduleName() external pure returns (string memory _moduleName) {
return 'BondedDisputeModule';
}

// /// @inheritdoc IBondedDisputeModule
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) {
// _params = abi.decode(requestData[_requestId], (RequestParameters));
// }
/// @inheritdoc IBondedDisputeModule
function decodeRequestData(bytes calldata _data) public view returns (RequestParameters memory _params) {
_params = abi.decode(_data, (RequestParameters));
}

// /// @inheritdoc IBondedDisputeModule
// function disputeEscalated(bytes32 _disputeId) external onlyOracle {}
/// @inheritdoc IBondedDisputeModule
function disputeResponse(
IOracle.Request calldata _request,
IOracle.Response calldata _response,

Check warning on line 26 in solidity/contracts/modules/dispute/BondedDisputeModule.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Variable "_response" is unused
IOracle.Dispute calldata _dispute
) external onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);

// /// @inheritdoc IBondedDisputeModule
// function disputeResponse(
// bytes32 _requestId,
// bytes32 _responseId,
// address _disputer,
// address _proposer
// ) external onlyOracle returns (IOracle.Dispute memory _dispute) {
// _dispute = IOracle.Dispute({
// disputer: _disputer,
// responseId: _responseId,
// proposer: _proposer,
// requestId: _requestId,
// status: IOracle.DisputeStatus.Active,
// createdAt: block.timestamp
// });
_params.accountingExtension.bond({
_bonder: _dispute.disputer,
_requestId: _dispute.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});

// RequestParameters memory _params = decodeRequestData(_requestId);
// _params.accountingExtension.bond({
// _bonder: _disputer,
// _requestId: _requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
emit ResponseDisputed({
_requestId: _dispute.requestId,
_responseId: _dispute.responseId,
_disputeId: _getId(_dispute),
_dispute: _dispute,
_blockNumber: block.number
});
}

// emit ResponseDisputed(_requestId, _responseId, _disputer, _proposer);
// }
/// @inheritdoc IBondedDisputeModule
function onDisputeStatusChange(
bytes32 _disputeId,
IOracle.Request calldata _request,
IOracle.Response calldata _response,

Check warning on line 51 in solidity/contracts/modules/dispute/BondedDisputeModule.sol

View workflow job for this annotation

GitHub Actions / Run Linters (16.x)

Variable "_response" is unused
IOracle.Dispute calldata _dispute
) external onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
IOracle.DisputeStatus _status = ORACLE.disputeStatus(_disputeId);

// /// @inheritdoc IBondedDisputeModule
// function onDisputeStatusChange(bytes32, /* _disputeId */ IOracle.Dispute memory _dispute) external onlyOracle {
// RequestParameters memory _params = decodeRequestData(_dispute.requestId);
// IOracle.DisputeStatus _status = _dispute.status;
// address _proposer = _dispute.proposer;
// address _disputer = _dispute.disputer;
if (_status == IOracle.DisputeStatus.NoResolution) {
// No resolution, we release both bonds
_params.accountingExtension.release({
_bonder: _dispute.disputer,
_requestId: _dispute.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});

// if (_status == IOracle.DisputeStatus.NoResolution) {
// // No resolution, we release both bonds
// _params.accountingExtension.release({
// _bonder: _disputer,
// _requestId: _dispute.requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
_params.accountingExtension.release({
_bonder: _dispute.proposer,
_requestId: _dispute.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
} else if (_status == IOracle.DisputeStatus.Won) {
// Disputer won, we pay the disputer and release their bond
_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_payer: _dispute.proposer,
_receiver: _dispute.disputer,
_token: _params.bondToken,
_amount: _params.bondSize
});
_params.accountingExtension.release({
_bonder: _dispute.disputer,
_requestId: _dispute.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
} else if (_status == IOracle.DisputeStatus.Lost) {
// Disputer lost, we pay the proposer and release their bond
_params.accountingExtension.pay({
_requestId: _dispute.requestId,
_payer: _dispute.disputer,
_receiver: _dispute.proposer,
_token: _params.bondToken,
_amount: _params.bondSize
});
_params.accountingExtension.release({
_bonder: _dispute.proposer,
_requestId: _dispute.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
}

// _params.accountingExtension.release({
// _bonder: _proposer,
// _requestId: _dispute.requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// } else if (_status == IOracle.DisputeStatus.Won) {
// // Disputer won, we pay the disputer and release their bond
// _params.accountingExtension.pay({
// _requestId: _dispute.requestId,
// _payer: _proposer,
// _receiver: _disputer,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// _params.accountingExtension.release({
// _bonder: _disputer,
// _requestId: _dispute.requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// } else if (_status == IOracle.DisputeStatus.Lost) {
// // Disputer lost, we pay the proposer and release their bond
// _params.accountingExtension.pay({
// _requestId: _dispute.requestId,
// _payer: _disputer,
// _receiver: _proposer,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// _params.accountingExtension.release({
// _bonder: _proposer,
// _requestId: _dispute.requestId,
// _token: _params.bondToken,
// _amount: _params.bondSize
// });
// }

// emit DisputeStatusChanged({
// _requestId: _dispute.requestId,
// _responseId: _dispute.responseId,
// _disputer: _disputer,
// _proposer: _proposer,
// _status: _status
// });
// }
// }
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: _status});
}
}
Loading

0 comments on commit 3cf4580

Please sign in to comment.