Skip to content

Commit

Permalink
chore: merge 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJabberwock committed Jul 26, 2024
2 parents be07792 + eff1822 commit 9ba8102
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 225 deletions.
5 changes: 3 additions & 2 deletions solidity/contracts/extensions/BondEscalationAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract BondEscalationAccounting is AccountingExtension, IBondEscalationAccount
mapping(bytes32 _disputeId => EscalationResult _result) public escalationResults;

/// @inheritdoc IBondEscalationAccounting
mapping(bytes32 _requestId => mapping(address _pledger => bool)) public pledgerClaimed;
mapping(bytes32 _requestId => mapping(address _pledger => bool _claimed)) public pledgerClaimed;

constructor(IOracle _oracle) AccountingExtension(_oracle) {}

Expand Down Expand Up @@ -84,7 +84,8 @@ contract BondEscalationAccounting is AccountingExtension, IBondEscalationAccount
uint256 _numberOfPledges;

if (_status == IOracle.DisputeStatus.NoResolution) {
_numberOfPledges = 1;
_numberOfPledges = _result.bondEscalationModule.pledgesForDispute(_requestId, _pledger)
+ _result.bondEscalationModule.pledgesAgainstDispute(_requestId, _pledger);
} else {
_numberOfPledges = _status == IOracle.DisputeStatus.Won
? _result.bondEscalationModule.pledgesForDispute(_requestId, _pledger)
Expand Down
20 changes: 9 additions & 11 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.responseCreatedAt(_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 @@ -126,7 +125,7 @@ contract BondEscalationModule is Module, IBondEscalationModule {
uint256 _pledgesForDispute = _escalation.amountOfPledgesForDispute;
uint256 _pledgesAgainstDispute = _escalation.amountOfPledgesAgainstDispute;

if (_pledgesAgainstDispute > 0) {
if (_pledgesAgainstDispute > 0 || _pledgesForDispute > 0) {
uint256 _amountToPay = _won
? _params.bondSize
+ FixedPointMathLib.mulDivDown(_pledgesAgainstDispute, _params.bondSize, _pledgesForDispute)
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
17 changes: 15 additions & 2 deletions solidity/contracts/modules/dispute/CircuitResolverModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,25 @@ contract CircuitResolverModule is Module, ICircuitResolverModule {
/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
view
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = address(_params.accountingExtension) != address(0) && address(_params.bondToken) != address(0)
&& _params.bondSize != 0 && address(_params.verifier) != address(0) && _params.callData.length != 0;
&& _params.bondSize != 0 && _targetHasBytecode(_params.verifier) && _params.callData.length != 0;
}

/**
* @notice Checks if a target address has bytecode
* @param _target The address to check
* @return _hasBytecode Whether the target has bytecode or not
*/
function _targetHasBytecode(address _target) private view returns (bool _hasBytecode) {
uint256 _size;
assembly {
_size := extcodesize(_target)
}
_hasBytecode = _size > 0;
}
}
18 changes: 16 additions & 2 deletions solidity/contracts/modules/finality/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract CallbackModule is Module, ICallbackModule {
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);
Expand All @@ -35,11 +36,24 @@ contract CallbackModule is Module, ICallbackModule {
/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
view
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = address(_params.target) != address(0) && _params.data.length != 0;
_valid = _params.data.length != 0 && _targetHasBytecode(_params.target);
}

/**
* @notice Checks if a target address has bytecode
* @param _target The address to check
* @return _hasBytecode Whether the target has bytecode or not
*/
function _targetHasBytecode(address _target) private view returns (bool _hasBytecode) {
uint256 _size;
assembly {
_size := extcodesize(_target)
}
_hasBytecode = _size > 0;
}
}
17 changes: 15 additions & 2 deletions solidity/contracts/modules/finality/MultipleCallbacksModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule {
/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
view
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = true;

for (uint256 _i; _i < _params.targets.length; ++_i) {
if (_params.targets[_i] == address(0)) {
if (!_targetHasBytecode(_params.targets[_i])) {
_valid = false;
break;
}
Expand All @@ -64,4 +64,17 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule {
}
}
}

/**
* @notice Checks if a target address has bytecode
* @param _target The address to check
* @return _hasBytecode Whether the target has bytecode or not
*/
function _targetHasBytecode(address _target) private view returns (bool _hasBytecode) {
uint256 _size;
assembly {
_size := extcodesize(_target)
}
_hasBytecode = _size > 0;
}
}
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.disputeCreatedAt(_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
2 changes: 1 addition & 1 deletion solidity/test/integration/IntegrationBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {TestConstants} from '../utils/TestConstants.sol';
// solhint-enable no-unused-import

contract IntegrationBase is DSTestPlus, TestConstants, Helpers {
uint256 public constant FORK_BLOCK = 100_000_000;
uint256 public constant FORK_BLOCK = 122_612_760;

uint256 internal _initialBalance = 100_000 ether;

Expand Down
Loading

0 comments on commit 9ba8102

Please sign in to comment.