Skip to content

Commit

Permalink
fix: comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ashitakah committed Jul 19, 2024
1 parent 092f58d commit 1ac841c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
8 changes: 2 additions & 6 deletions solidity/contracts/modules/finality/CallbackModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ contract CallbackModule is Module, ICallbackModule {
) 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 @@ -40,12 +36,12 @@ 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);
}

/**
Expand Down
10 changes: 2 additions & 8 deletions solidity/contracts/modules/finality/MultipleCallbacksModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ 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 All @@ -49,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 Down
10 changes: 9 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 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

0 comments on commit 1ac841c

Please sign in to comment.