Skip to content

Commit

Permalink
fix: improve logic in RootVerificationModule and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent committed Nov 10, 2023
1 parent 388e99b commit 2866715
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 355 deletions.
19 changes: 9 additions & 10 deletions solidity/contracts/modules/dispute/RootVerificationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,16 @@ contract RootVerificationModule is Module, IRootVerificationModule {
response: abi.encode(_correctRoot)
});

ORACLE.proposeResponse(_dispute.disputer, _request, _newResponse);
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 _correctRoots[_dispute.requestId];

// TODO: Emit event
// emit DisputeStatusChanged({
// _disputeId: _disputeId,
// _dispute: _dispute,
// _status: IOracle.DisputeStatus.Resolved
// });
}

/// @inheritdoc IRootVerificationModule
Expand All @@ -83,14 +79,17 @@ contract RootVerificationModule is Module, IRootVerificationModule {
bytes32 _correctRoot = _params.treeVerifier.calculateRoot(_params.treeData, _params.leavesToInsert);
_correctRoots[_response.requestId] = _correctRoot;

bool _won = abi.decode(_response.response, (bytes32)) != _correctRoot;
IOracle.DisputeStatus _status =
abi.decode(_response.response, (bytes32)) != _correctRoot ? IOracle.DisputeStatus.Won : IOracle.DisputeStatus.Lost;

// TODO: call ORACLE.updateDisputeStatus
emit ResponseDisputed({
_requestId: _response.requestId,
_responseId: _dispute.responseId,
_disputeId: _getId(_dispute),
_dispute: _dispute,
_blockNumber: block.number
});

ORACLE.updateDisputeStatus(_request, _response, _dispute, _status);
}
}
28 changes: 21 additions & 7 deletions solidity/interfaces/modules/dispute/IRootVerificationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {IAccountingExtension} from '../../extensions/IAccountingExtension.sol';

/*
* @title RootVerificationModule
* @notice Dispute module allowing disputers to calculate the correct root
* for a given request and propose it as a response. If the disputer wins the
* dispute, he is rewarded with the bond of the proposer.
* @dev This module is a pre-dispute module. It allows disputing
* and resolving a response in a single call.
* @notice Dispute module allowing disputers to calculate the correct root for a given request and propose it as a response.
* If the disputer wins the dispute, he is rewarded with the bond of the proposer.
*
* @dev This module is a pre-dispute module. It allows disputing and resolving a response in a single call.
*/
interface IRootVerificationModule is IDisputeModule {
/*///////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -50,14 +49,29 @@ interface IRootVerificationModule is IDisputeModule {
*/
function decodeRequestData(bytes calldata _data) external view returns (RequestParameters memory _params);

/// @inheritdoc IDisputeModule
/**
* @notice Initiates and resolves the dispute by comparing the proposed response with the one returned by the verifier
*
* @dev This function will notify the oracle about the outcome of the dispute
* @param _request The request that the response was proposed to
* @param _response The response that is being disputed
* @param _dispute The dispute created by the oracle
*/
function disputeResponse(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external;

/// @inheritdoc IDisputeModule
/**
* @notice Depending on the status of the dispute, either pays the disputer and submits the correct response,
* or pays the proposer. Finalizes the request in any case.
*
* @param _disputeId The id of the dispute
* @param _request The request that the response was proposed to
* @param _response The response that was disputed
* @param _dispute The dispute
*/
function onDisputeStatusChange(
bytes32 _disputeId,
IOracle.Request calldata _request,
Expand Down
Loading

0 comments on commit 2866715

Please sign in to comment.