Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: not eoa #52

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
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 = address(_params.target) != address(0) && _params.data.length != 0 && _targetHasBytecode(_params.target);
0xJabberwock marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @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 (_params.targets[_i] == address(0) || !_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;
}
}
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
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