Skip to content

Commit

Permalink
feat: not eoa
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 19, 2024
1 parent 1dffdc6 commit 092f58d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
18 changes: 18 additions & 0 deletions solidity/contracts/modules/finality/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ contract CallbackModule is Module, ICallbackModule {
address _finalizer
) external override(Module, ICallbackModule) onlyOracle {
RequestParameters memory _params = decodeRequestData(_request.finalityModuleData);

if (!_targetHasBytecode(_params.target)) {
emit RequestFinalized(_response.requestId, _response, _finalizer);
return;
}
_params.target.call(_params.data);
emit Callback(_response.requestId, _params.target, _params.data);
emit RequestFinalized(_response.requestId, _response, _finalizer);
Expand All @@ -42,4 +47,17 @@ contract CallbackModule is Module, ICallbackModule {
RequestParameters memory _params = decodeRequestData(_encodedParameters);
_valid = address(_params.target) != address(0) && _params.data.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;
}
}
19 changes: 19 additions & 0 deletions solidity/contracts/modules/finality/MultipleCallbacksModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ contract MultipleCallbacksModule is Module, IMultipleCallbacksModule {
uint256 _length = _params.targets.length;

for (uint256 _i; _i < _length;) {
if (!_targetHasBytecode(_params.targets[_i])) {
unchecked {
++_i;
}
continue;
}
_params.targets[_i].call(_params.data[_i]);
emit Callback(_response.requestId, _params.targets[_i], _params.data[_i]);
unchecked {
Expand Down Expand Up @@ -64,4 +70,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;
}
}
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
1 change: 1 addition & 0 deletions solidity/test/unit/modules/finality/CallbackModule.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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

0 comments on commit 092f58d

Please sign in to comment.