Skip to content

Commit

Permalink
EVMHost: Reduce code duplication in precompiles
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Sep 26, 2022
1 parent a260000 commit c967a62
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions test/EVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,14 @@ evmc::result EVMHost::precompileECRecover(evmc_message const& _message) noexcept
}
};
evmc::result result = precompileGeneric(_message, inputOutput);
result.status_code = EVMC_SUCCESS;
result.gas_left = _message.gas;
// ECRecover will return success with empty response in case of failure
if (result.status_code != EVMC_SUCCESS)
{
result.status_code = EVMC_SUCCESS;
result.gas_left = _message.gas;
result.output_data = {};
result.output_size = 0;
}
return result;
}

Expand All @@ -408,12 +414,7 @@ evmc::result EVMHost::precompileSha256(evmc_message const& _message) noexcept
_message.input_data + _message.input_size
));

evmc::result result({});
result.status_code = EVMC_SUCCESS;
result.gas_left = _message.gas;
result.output_data = hash.data();
result.output_size = hash.size();
return result;
return resultWithGas(_message, hash);
}

evmc::result EVMHost::precompileRipeMD160(evmc_message const& _message) noexcept
Expand Down Expand Up @@ -488,12 +489,7 @@ evmc::result EVMHost::precompileIdentity(evmc_message const& _message) noexcept
bytes static data;
data = bytes(_message.input_data, _message.input_data + _message.input_size);

evmc::result result({});
result.status_code = EVMC_SUCCESS;
result.gas_left = _message.gas;
result.output_data = data.data();
result.output_size = data.size();
return result;
return resultWithGas(_message, data);
}

evmc::result EVMHost::precompileModExp(evmc_message const&) noexcept
Expand Down

0 comments on commit c967a62

Please sign in to comment.