Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 24, 2024
1 parent 1ac841c commit 83fc2d0
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 127 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-4d4a4487",
"@defi-wonderland/prophet-core-contracts": "0.0.0-ad40b65b",
"@openzeppelin/contracts": "4.9.5",
"solmate": "https://github.com/transmissions11/solmate.git#bfc9c25865a274a7827fea5abf6e4fb64fc64e6c"
},
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;
}
}
2 changes: 1 addition & 1 deletion solidity/contracts/modules/finality/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract CallbackModule is Module, ICallbackModule {
returns (bool _valid)
{
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = address(_params.target) != address(0) && _params.data.length != 0 && _targetHasBytecode(_params.target);
_valid = _params.data.length != 0 && _targetHasBytecode(_params.target);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule {
_valid = true;

for (uint256 _i; _i < _params.targets.length; ++_i) {
if (_params.targets[_i] == address(0) || !_targetHasBytecode(_params.targets[_i])) {
if (!_targetHasBytecode(_params.targets[_i])) {
_valid = false;
break;
}
Expand Down
10 changes: 9 additions & 1 deletion solidity/test/unit/modules/dispute/CircuitResolverModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ contract BaseTest is Test, Helpers {

circuitResolverModule = new ForTest_CircuitResolverModule(oracle);
}

function targetHasBytecode(address _target) public view returns (bool _hasBytecode) {
uint256 _size;
assembly {
_size := extcodesize(_target)
}
_hasBytecode = _size > 0;
}
}

contract CircuitResolverModule_Unit_ModuleData is BaseTest {
Expand Down Expand Up @@ -109,7 +117,7 @@ contract CircuitResolverModule_Unit_ModuleData is BaseTest {
function test_validateParameters(ICircuitResolverModule.RequestParameters calldata _params) public {
if (
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
) {
assertFalse(circuitResolverModule.validateParameters(abi.encode(_params)));
} else {
Expand Down
Loading

0 comments on commit 83fc2d0

Please sign in to comment.