Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: request id validation #51

Merged
merged 10 commits into from
Jul 26, 2024
18 changes: 8 additions & 10 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
BondEscalation storage _escalation = _escalations[_dispute.requestId];

if (block.number > ORACLE.createdAt(_dispute.responseId) + _params.disputeWindow) {
revert BondEscalationModule_DisputeWindowOver();
}

BondEscalation storage _escalation = _escalations[_dispute.requestId];
bytes32 _disputeId = _getId(_dispute);

_params.accountingExtension.bond({
_bonder: _dispute.disputer,
_requestId: _dispute.requestId,
Expand Down Expand Up @@ -212,7 +211,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
/// @inheritdoc IBondEscalationModule
function pledgeForDispute(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_disputeId, _request, _dispute, true);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, true);

_escalations[_dispute.requestId].amountOfPledgesForDispute += 1;
pledgesForDispute[_dispute.requestId][msg.sender] += 1;
Expand All @@ -230,7 +229,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
/// @inheritdoc IBondEscalationModule
function pledgeAgainstDispute(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _disputeId = _getId(_dispute);
RequestParameters memory _params = _pledgeChecks(_disputeId, _request, _dispute, false);
RequestParameters memory _params = _pledgeChecks(_request, _dispute, false);

_escalations[_dispute.requestId].amountOfPledgesAgainstDispute += 1;
pledgesAgainstDispute[_dispute.requestId][msg.sender] += 1;
Expand All @@ -251,9 +250,9 @@ contract BondEscalationModule is Module, IBondEscalationModule {
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external {
bytes32 _requestId = _getId(_request);
(, bytes32 _disputeId) = _validateResponseAndDispute(_request, _response, _dispute);
RequestParameters memory _params = decodeRequestData(_request.disputeModuleData);
BondEscalation storage _escalation = _escalations[_requestId];
BondEscalation storage _escalation = _escalations[_dispute.requestId];

if (block.timestamp <= _params.bondEscalationDeadline + _params.tyingBuffer) {
revert BondEscalationModule_BondEscalationNotOver();
Expand All @@ -273,7 +272,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
bool _disputersWon = _pledgesForDispute > _pledgesAgainstDispute;
_escalation.status = _disputersWon ? BondEscalationStatus.DisputerWon : BondEscalationStatus.DisputerLost;

emit BondEscalationStatusUpdated(_requestId, _escalation.disputeId, _escalation.status);
emit BondEscalationStatusUpdated(_dispute.requestId, _disputeId, _escalation.status);

ORACLE.updateDisputeStatus(
_request, _response, _dispute, _disputersWon ? IOracle.DisputeStatus.Won : IOracle.DisputeStatus.Lost
Expand All @@ -282,18 +281,17 @@ contract BondEscalationModule is Module, IBondEscalationModule {

/**
* @notice Checks the necessary conditions for pledging
* @param _disputeId The ID of the dispute to pledge for or against
* @param _request The request data
* @param _dispute The dispute data
* @param _forDispute Whether the pledge is for or against the dispute
* @return _params The decoded parameters for the request
*/
function _pledgeChecks(
bytes32 _disputeId,
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute,
bool _forDispute
) internal view returns (RequestParameters memory _params) {
bytes32 _disputeId = _validateDispute(_request, _dispute);
BondEscalation memory _escalation = _escalations[_dispute.requestId];

if (_disputeId != _escalation.disputeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external onlyOracle {
bytes32 _requestId = _dispute.requestId;

Escalation storage _escalation = escalations[_disputeId];

if (_escalation.resolution != Resolution.Unresolved) revert BondEscalationResolutionModule_AlreadyResolved();
Expand Down Expand Up @@ -119,13 +117,12 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
}

ORACLE.updateDisputeStatus(_request, _response, _dispute, _disputeStatus);
emit DisputeResolved(_requestId, _disputeId, _disputeStatus);
emit DisputeResolved(_dispute.requestId, _disputeId, _disputeStatus);
}

/// @inheritdoc IBondEscalationResolutionModule
function claimPledge(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _disputeId = _getId(_dispute);
bytes32 _requestId = _dispute.requestId;
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation storage _escalation = escalations[_disputeId];

if (_escalation.resolution == Resolution.Unresolved) revert BondEscalationResolutionModule_NotResolved();
Expand All @@ -143,7 +140,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
_reward = FixedPointMathLib.mulDivDown(_escalation.pledgesAgainst, _pledgerProportion, BASE);
_amountToRelease = _reward + _pledgerBalanceBefore;
_claimPledge({
_requestId: _requestId,
_requestId: _dispute.requestId,
_disputeId: _disputeId,
_amountToRelease: _amountToRelease,
_resolution: _escalation.resolution,
Expand All @@ -156,7 +153,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
_reward = FixedPointMathLib.mulDivDown(_escalation.pledgesFor, _pledgerProportion, BASE);
_amountToRelease = _reward + _pledgerBalanceBefore;
_claimPledge({
_requestId: _requestId,
_requestId: _dispute.requestId,
_disputeId: _disputeId,
_amountToRelease: _amountToRelease,
_resolution: _escalation.resolution,
Expand All @@ -169,7 +166,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
if (_pledgerBalanceFor > 0) {
pledgesForDispute[_disputeId][msg.sender] -= _pledgerBalanceFor;
_claimPledge({
_requestId: _requestId,
_requestId: _dispute.requestId,
_disputeId: _disputeId,
_amountToRelease: _pledgerBalanceFor,
_resolution: _escalation.resolution,
Expand All @@ -180,7 +177,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
if (_pledgerBalanceAgainst > 0) {
pledgesAgainstDispute[_disputeId][msg.sender] -= _pledgerBalanceAgainst;
_claimPledge({
_requestId: _requestId,
_requestId: _dispute.requestId,
_disputeId: _disputeId,
_amountToRelease: _pledgerBalanceAgainst,
_resolution: _escalation.resolution,
Expand All @@ -204,8 +201,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
uint256 _pledgeAmount,
bool _pledgingFor
) internal {
bytes32 _disputeId = _getId(_dispute);
bytes32 _requestId = _dispute.requestId;
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation storage _escalation = escalations[_disputeId];

if (_escalation.startTime == 0) revert BondEscalationResolutionModule_NotEscalated();
Expand All @@ -224,7 +220,7 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu

_params.accountingExtension.pledge({
_pledger: msg.sender,
_requestId: _requestId,
_requestId: _dispute.requestId,
_disputeId: _disputeId,
_token: _params.bondToken,
_amount: _pledgeAmount
Expand All @@ -237,15 +233,15 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu

_escalation.pledgesFor += _pledgeAmount;
pledgesForDispute[_disputeId][msg.sender] += _pledgeAmount;
emit PledgedForDispute(msg.sender, _requestId, _disputeId, _pledgeAmount);
emit PledgedForDispute(msg.sender, _dispute.requestId, _disputeId, _pledgeAmount);
} else {
if (_inequalityData.inequalityStatus == InequalityStatus.ForTurnToEqualize) {
revert BondEscalationResolutionModule_ForTurnToEqualize();
}

_escalation.pledgesAgainst += _pledgeAmount;
pledgesAgainstDispute[_disputeId][msg.sender] += _pledgeAmount;
emit PledgedAgainstDispute(msg.sender, _requestId, _disputeId, _pledgeAmount);
emit PledgedAgainstDispute(msg.sender, _dispute.requestId, _disputeId, _pledgeAmount);
}

if (_escalation.pledgesFor + _escalation.pledgesAgainst >= _params.pledgeThreshold) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
IOracle.Dispute calldata _dispute,
uint256 _numberOfVotes
) public {
bytes32 _disputeId = _getId(_dispute);
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation memory _escalation = escalations[_disputeId];
if (_escalation.startTime == 0) revert ERC20ResolutionModule_DisputeNotEscalated();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
Expand Down Expand Up @@ -111,7 +111,7 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {

/// @inheritdoc IERC20ResolutionModule
function claimVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute) external {
bytes32 _disputeId = _getId(_dispute);
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation memory _escalation = escalations[_disputeId];

// Check that voting deadline is over
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {

/// @inheritdoc IPrivateERC20ResolutionModule
function commitVote(IOracle.Request calldata _request, IOracle.Dispute calldata _dispute, bytes32 _commitment) public {
bytes32 _disputeId = _getId(_dispute);
bytes32 _disputeId = _validateDispute(_request, _dispute);
if (ORACLE.createdAt(_disputeId) == 0) revert PrivateERC20ResolutionModule_NonExistentDispute();
if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Escalated) {
revert PrivateERC20ResolutionModule_AlreadyResolved();
Expand All @@ -78,7 +78,7 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
uint256 _numberOfVotes,
bytes32 _salt
) public {
bytes32 _disputeId = _getId(_dispute);
bytes32 _disputeId = _validateDispute(_request, _dispute);
Escalation memory _escalation = escalations[_disputeId];
if (_escalation.startTime == 0) revert PrivateERC20ResolutionModule_DisputeNotEscalated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ interface IERC20ResolutionModule is IResolutionModule {
ERRORS
//////////////////////////////////////////////////////////////*/

/**
* @notice Throws if the caller is not the dispute module
*/
error ERC20ResolutionModule_OnlyDisputeModule();

/**
* @notice Throws if the dispute doesn't exist or has not been escalated
*/
Expand Down
Loading
Loading