Skip to content

Commit

Permalink
feat: not eoa (#52)
Browse files Browse the repository at this point in the history
* feat: not eoa

* fix: comments

* fix: comments
  • Loading branch information
ashitakah authored Jul 24, 2024
1 parent 07e210d commit fbdedb5
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 131 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;
}
}
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;
}
}
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
11 changes: 10 additions & 1 deletion solidity/test/unit/modules/finality/CallbackModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ contract BaseTest is Test, Helpers {

callbackModule = new CallbackModule(oracle);
}

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

contract CallbackModule_Unit_ModuleData is BaseTest {
Expand Down Expand Up @@ -60,7 +68,7 @@ contract CallbackModule_Unit_ModuleData is BaseTest {
* @notice Test that the validateParameters function correctly checks the parameters
*/
function test_validateParameters(ICallbackModule.RequestParameters calldata _params) public {
if (address(_params.target) == address(0) || _params.data.length == 0) {
if (address(_params.target) == address(0) || _params.data.length == 0 || !targetHasBytecode(_params.target)) {
assertFalse(callbackModule.validateParameters(abi.encode(_params)));
} else {
assertTrue(callbackModule.validateParameters(abi.encode(_params)));
Expand All @@ -73,6 +81,7 @@ contract CallbackModule_Unit_FinalizeRequest is BaseTest {
* @notice Test that finalizeRequest emits events
*/
function test_emitsEvents(address _proposer, address _target, bytes calldata _data) public assumeFuzzable(_target) {
vm.etch(_target, '0xabcdef');
mockRequest.finalityModuleData = abi.encode(ICallbackModule.RequestParameters({target: _target, data: _data}));
mockResponse.requestId = _getId(mockRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ contract BaseTest is Test, Helpers {

multipleCallbackModule = new MultipleCallbacksModule(oracle);
}

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

/**
Expand All @@ -50,7 +58,7 @@ contract MultipleCallbacksModule_Unit_ModuleData is BaseTest {
function test_validateParameters(IMultipleCallbacksModule.RequestParameters calldata _params) public {
bool _valid = true;
for (uint256 _i; _i < _params.targets.length; ++_i) {
if (_params.targets[_i] == address(0)) {
if (_params.targets[_i] == address(0) || !targetHasBytecode(_params.targets[_i])) {
_valid = false;
}
}
Expand Down
Loading

0 comments on commit fbdedb5

Please sign in to comment.