Skip to content

Commit

Permalink
feat: parameters validation implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmoebius committed Dec 14, 2023
1 parent 5fe04cb commit 1360211
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-ad870035",
"@defi-wonderland/prophet-core-contracts": "0.0.0-6ac0f50d",
"@defi-wonderland/solidity-utils": "0.0.0-3e9c8e8b",
"@openzeppelin/contracts": "^4.9.3",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
Expand Down
15 changes: 15 additions & 0 deletions solidity/contracts/modules/dispute/BondEscalationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,19 @@ contract BondEscalationModule is Module, IBondEscalationModule {
function getEscalation(bytes32 _requestId) public view returns (BondEscalation memory _escalation) {
_escalation = _escalations[_requestId];
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
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 || _params.bondEscalationDeadline == 0 || _params.maxNumberOfEscalations == 0
|| _params.tyingBuffer == 0 || _params.disputeWindow == 0
) ? false : true;
}
}
14 changes: 14 additions & 0 deletions solidity/contracts/modules/dispute/BondedDisputeModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,18 @@ contract BondedDisputeModule is Module, IBondedDisputeModule {

emit DisputeStatusChanged({_disputeId: _disputeId, _dispute: _dispute, _status: _status});
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
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
) ? false : true;
}
}
14 changes: 14 additions & 0 deletions solidity/contracts/modules/dispute/CircuitResolverModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,18 @@ contract CircuitResolverModule is Module, ICircuitResolverModule {

ORACLE.updateDisputeStatus(_request, _response, _dispute, _status);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
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
) ? false : true;
}
}
15 changes: 15 additions & 0 deletions solidity/contracts/modules/dispute/RootVerificationModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,19 @@ contract RootVerificationModule is Module, IRootVerificationModule {

ORACLE.updateDisputeStatus(_request, _response, _dispute, _status);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0)
|| address(_params.treeVerifier) == address(0) || _params.bondSize == 0 || _params.treeData.length == 0
|| _params.leavesToInsert.length == 0
) ? false : true;
}
}
11 changes: 11 additions & 0 deletions solidity/contracts/modules/finality/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ contract CallbackModule is Module, ICallbackModule {
emit Callback(_response.requestId, _params.target, _params.data);
emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (address(_params.target) == address(0) || _params.data.length == 0) ? false : true;
}
}
25 changes: 25 additions & 0 deletions solidity/contracts/modules/finality/MultipleCallbacksModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,29 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule {

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
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)) {
_valid = false;
break;
}
}

for (uint256 _i; _i < _params.data.length; ++_i) {
if (_params.data[_i].length == 0) {
_valid = false;
break;
}
}
}
}
14 changes: 14 additions & 0 deletions solidity/contracts/modules/request/ContractCallRequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,18 @@ contract ContractCallRequestModule is Module, IContractCallRequestModule {

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0)
|| _params.target == address(0) || _params.paymentAmount == 0 || _params.functionSelector == bytes4(0)
) ? false : true;
}
}
15 changes: 15 additions & 0 deletions solidity/contracts/modules/request/HttpRequestModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ contract HttpRequestModule is Module, IHttpRequestModule {

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0)
|| _params.paymentAmount == 0 || keccak256(abi.encode(_params.url)) == keccak256(abi.encode(''))
|| keccak256(abi.encode(_params.body)) == keccak256(abi.encode(''))
) ? false : true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ contract SparseMerkleTreeRequestModule is Module, ISparseMerkleTreeRequestModule

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.paymentToken) == address(0)
|| address(_params.treeVerifier) == address(0) || _params.paymentAmount == 0 || _params.treeData.length == 0
|| _params.leavesToInsert.length == 0
) ? false : true;
}
}
11 changes: 11 additions & 0 deletions solidity/contracts/modules/resolution/ArbitratorModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ contract ArbitratorModule is Module, IArbitratorModule {

emit DisputeResolved(_dispute.requestId, _disputeId, _status);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = _params.arbitrator == address(0) ? false : true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,19 @@ contract BondEscalationResolutionModule is Module, IBondEscalationResolutionModu
_resolution: _resolution
});
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.bondToken) == address(0)
|| _params.percentageDiff == 0 || _params.pledgeThreshold == 0 || _params.timeUntilDeadline == 0
|| _params.timeToBreakInequality == 0
) ? false : true;
}
}
14 changes: 14 additions & 0 deletions solidity/contracts/modules/resolution/ERC20ResolutionModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,18 @@ contract ERC20ResolutionModule is Module, IERC20ResolutionModule {
function getVoters(bytes32 _disputeId) external view returns (address[] memory __voters) {
__voters = _voters[_disputeId].values();
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.votingToken) == address(0)
|| _params.minVotesForQuorum == 0 || _params.timeUntilDeadline == 0
) ? false : true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,18 @@ contract PrivateERC20ResolutionModule is Module, IPrivateERC20ResolutionModule {
) external view returns (bytes32 _commitment) {
_commitment = keccak256(abi.encode(msg.sender, _disputeId, _numberOfVotes, _salt));
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
override(Module, IModule)
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = (
address(_params.accountingExtension) == address(0) || address(_params.votingToken) == address(0)
|| _params.minVotesForQuorum == 0 || _params.committingTimeWindow == 0 || _params.revealingTimeWindow == 0
) ? false : true;
}
}
14 changes: 14 additions & 0 deletions solidity/contracts/modules/response/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ contract BondedResponseModule is Module, IBondedResponseModule {

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IModule
function validateParameters(bytes calldata _encodedParameters)
external
pure
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 || _params.disputeWindow == 0 || _params.deadline == 0
) ? false : true;
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@defi-wonderland/[email protected]ad870035":
version "0.0.0-ad870035"
resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-ad870035.tgz#b3ed33f46310bbac137f4c5952bd75c5cd608507"
integrity sha512-tfGPXUYB8zF7+NSGzTNKZfYDJ4/yihmf2ZQevTmHn8gzkNEzQeBYf3qi/hslxXQ0HwnHfJd7VftCQDy/kVcr8g==
"@defi-wonderland/[email protected]6ac0f50d":
version "0.0.0-6ac0f50d"
resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-6ac0f50d.tgz#64c903e6d529628f192e3d083959cdec7105bf99"
integrity sha512-FsiOHl4h1s64CoNpCmuSB+Q0v6Mg4PLAcT4v9x5FA7iTMpexVy8dq+GyXDNch82bpaOojic8rwh4jm+eB4bT8g==

"@defi-wonderland/[email protected]":
version "0.0.0-3e9c8e8b"
Expand Down

0 comments on commit 1360211

Please sign in to comment.