-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into perf/opo-596-root-verification-module
- Loading branch information
Showing
15 changed files
with
1,233 additions
and
1,612 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
184 changes: 93 additions & 91 deletions
184
solidity/contracts/modules/dispute/CircuitResolverModule.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,93 @@ | ||
// // 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'; | ||
|
||
// import {ICircuitResolverModule} from '../../../interfaces/modules/dispute/ICircuitResolverModule.sol'; | ||
|
||
// contract CircuitResolverModule is Module, ICircuitResolverModule { | ||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// mapping(bytes32 _requestId => bytes _correctResponse) internal _correctResponses; | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() external pure returns (string memory _moduleName) { | ||
// return 'CircuitResolverModule'; | ||
// } | ||
|
||
// /// @inheritdoc ICircuitResolverModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) { | ||
// _params = abi.decode(requestData[_requestId], (RequestParameters)); | ||
// } | ||
|
||
// /// @inheritdoc ICircuitResolverModule | ||
// function disputeEscalated(bytes32 _disputeId) external onlyOracle {} | ||
|
||
// /// @inheritdoc ICircuitResolverModule | ||
// function onDisputeStatusChange(bytes32, /* _disputeId */ IOracle.Dispute memory _dispute) external onlyOracle { | ||
// RequestParameters memory _params = decodeRequestData(_dispute.requestId); | ||
|
||
// IOracle.Response memory _response = ORACLE.getResponse(_dispute.responseId); | ||
|
||
// bytes memory _correctResponse = _correctResponses[_dispute.requestId]; | ||
// bool _won = _response.response.length != _correctResponse.length | ||
// || keccak256(_response.response) != keccak256(_correctResponse); | ||
|
||
// if (_won) { | ||
// _params.accountingExtension.pay({ | ||
// _requestId: _dispute.requestId, | ||
// _payer: _dispute.proposer, | ||
// _receiver: _dispute.disputer, | ||
// _token: _params.bondToken, | ||
// _amount: _params.bondSize | ||
// }); | ||
// bytes32 _correctResponseId = | ||
// ORACLE.proposeResponse(_dispute.disputer, _dispute.requestId, abi.encode(_correctResponses[_dispute.requestId])); | ||
// ORACLE.finalize(_dispute.requestId, _correctResponseId); | ||
// } else { | ||
// ORACLE.finalize(_dispute.requestId, _dispute.responseId); | ||
// } | ||
|
||
// delete _correctResponses[_dispute.requestId]; | ||
|
||
// emit DisputeStatusChanged({ | ||
// _requestId: _dispute.requestId, | ||
// _responseId: _dispute.responseId, | ||
// _disputer: _dispute.disputer, | ||
// _proposer: _dispute.proposer, | ||
// _status: _dispute.status | ||
// }); | ||
// } | ||
|
||
// /// @inheritdoc ICircuitResolverModule | ||
// function disputeResponse( | ||
// bytes32 _requestId, | ||
// bytes32 _responseId, | ||
// address _disputer, | ||
// address _proposer | ||
// ) external onlyOracle returns (IOracle.Dispute memory _dispute) { | ||
// IOracle.Response memory _response = ORACLE.getResponse(_responseId); | ||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
|
||
// (, bytes memory _correctResponse) = _params.verifier.call(_params.callData); | ||
// _correctResponses[_requestId] = _correctResponse; | ||
|
||
// bool _won = _response.response.length != _correctResponse.length | ||
// || keccak256(_response.response) != keccak256(_correctResponse); | ||
|
||
// _dispute = IOracle.Dispute({ | ||
// disputer: _disputer, | ||
// responseId: _responseId, | ||
// proposer: _proposer, | ||
// requestId: _requestId, | ||
// status: _won ? IOracle.DisputeStatus.Won : IOracle.DisputeStatus.Lost, | ||
// createdAt: block.timestamp | ||
// }); | ||
|
||
// emit ResponseDisputed(_requestId, _responseId, _disputer, _proposer); | ||
// } | ||
// } | ||
// 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'; | ||
|
||
import {ICircuitResolverModule} from '../../../interfaces/modules/dispute/ICircuitResolverModule.sol'; | ||
|
||
contract CircuitResolverModule is Module, ICircuitResolverModule { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
mapping(bytes32 _requestId => bytes _correctResponse) internal _correctResponses; | ||
|
||
/// @inheritdoc IModule | ||
function moduleName() external pure returns (string memory _moduleName) { | ||
return 'CircuitResolverModule'; | ||
} | ||
|
||
/// @inheritdoc ICircuitResolverModule | ||
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
/// @inheritdoc ICircuitResolverModule | ||
function onDisputeStatusChange( | ||
bytes32 _disputeId, | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
// TODO: Call `disputeStatus` to check the current status instead of reading from `_correctResponses` | ||
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData); | ||
|
||
bytes memory _correctResponse = _correctResponses[_dispute.requestId]; | ||
bool _won = _response.response.length != _correctResponse.length | ||
|| keccak256(_response.response) != keccak256(_correctResponse); | ||
|
||
if (_won) { | ||
_params.accountingExtension.pay({ | ||
_requestId: _dispute.requestId, | ||
_payer: _dispute.proposer, | ||
_receiver: _dispute.disputer, | ||
_token: _params.bondToken, | ||
_amount: _params.bondSize | ||
}); | ||
|
||
IOracle.Response memory _newResponse = | ||
IOracle.Response({requestId: _dispute.requestId, proposer: _dispute.disputer, response: _correctResponse}); | ||
|
||
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: IOracle.DisputeStatus.Won}); | ||
|
||
ORACLE.proposeResponse(_request, _newResponse); | ||
ORACLE.finalize(_request, _newResponse); | ||
} else { | ||
emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: IOracle.DisputeStatus.Lost}); | ||
|
||
ORACLE.finalize(_request, _response); | ||
} | ||
|
||
delete _correctResponses[_dispute.requestId]; | ||
} | ||
|
||
/// @inheritdoc ICircuitResolverModule | ||
function disputeResponse( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
IOracle.Dispute calldata _dispute | ||
) external onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData); | ||
|
||
(bool _success, bytes memory _correctResponse) = _params.verifier.call(_params.callData); | ||
|
||
if (!_success) revert CircuitResolverModule_VerificationFailed(); | ||
|
||
_correctResponses[_response.requestId] = _correctResponse; | ||
|
||
IOracle.DisputeStatus _status = _response.response.length != _correctResponse.length | ||
|| keccak256(_response.response) != keccak256(_correctResponse) | ||
? IOracle.DisputeStatus.Won | ||
: IOracle.DisputeStatus.Lost; | ||
|
||
emit ResponseDisputed({ | ||
_requestId: _response.requestId, | ||
_responseId: _dispute.responseId, | ||
_disputeId: _getId(_dispute), | ||
_dispute: _dispute, | ||
_blockNumber: block.number | ||
}); | ||
|
||
ORACLE.updateDisputeStatus(_request, _response, _dispute, _status); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,34 @@ | ||
// // 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 {ICallbackModule} from '../../../interfaces/modules/finality/ICallbackModule.sol'; | ||
import {ICallbackModule} from '../../../interfaces/modules/finality/ICallbackModule.sol'; | ||
|
||
// contract CallbackModule is Module, ICallbackModule { | ||
// constructor(IOracle _oracle) Module(_oracle) {} | ||
contract CallbackModule is Module, ICallbackModule { | ||
constructor(IOracle _oracle) Module(_oracle) {} | ||
|
||
// /// @inheritdoc IModule | ||
// function moduleName() public pure returns (string memory _moduleName) { | ||
// _moduleName = 'CallbackModule'; | ||
// } | ||
/// @inheritdoc IModule | ||
function moduleName() public pure returns (string memory _moduleName) { | ||
_moduleName = 'CallbackModule'; | ||
} | ||
|
||
// /// @inheritdoc ICallbackModule | ||
// function decodeRequestData(bytes32 _requestId) public view returns (RequestParameters memory _params) { | ||
// _params = abi.decode(requestData[_requestId], (RequestParameters)); | ||
// } | ||
/// @inheritdoc ICallbackModule | ||
function decodeRequestData(bytes calldata _data) public pure returns (RequestParameters memory _params) { | ||
_params = abi.decode(_data, (RequestParameters)); | ||
} | ||
|
||
// /** | ||
// * @notice Checks if the target address has code (i.e. is a contract) | ||
// * @param _data The encoded data for the request | ||
// */ | ||
// function _afterSetupRequest(bytes32, bytes calldata _data) internal view override { | ||
// RequestParameters memory _params = abi.decode(_data, (RequestParameters)); | ||
// if (_params.target.code.length == 0) revert CallbackModule_TargetHasNoCode(); | ||
// } | ||
|
||
// /// @inheritdoc ICallbackModule | ||
// function finalizeRequest( | ||
// bytes32 _requestId, | ||
// address _finalizer | ||
// ) external override(Module, ICallbackModule) onlyOracle { | ||
// RequestParameters memory _params = decodeRequestData(_requestId); | ||
// _params.target.call(_params.data); | ||
// emit Callback(_requestId, _params.target, _params.data); | ||
// emit RequestFinalized(_requestId, _finalizer); | ||
// } | ||
// } | ||
/// @inheritdoc ICallbackModule | ||
function finalizeRequest( | ||
IOracle.Request calldata _request, | ||
IOracle.Response calldata _response, | ||
address _finalizer | ||
) external override(Module, ICallbackModule) onlyOracle { | ||
RequestParameters memory _params = decodeRequestData(_request.finalityModuleData); | ||
_params.target.call(_params.data); | ||
emit Callback(_response.requestId, _params.target, _params.data); | ||
emit RequestFinalized(_response.requestId, _response, _finalizer); | ||
} | ||
} |
Oops, something went wrong.