Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Adding "codeFile" parameter into aleth-vm options (#5848)
Browse files Browse the repository at this point in the history
Adding "codeFile" parameter into aleth-vm options
  • Loading branch information
gumb0 authored Nov 27, 2019
2 parents d3553a5 + a4e6d35 commit 1614343
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Changed: [#5807](https://github.com/ethereum/aleth/pull/5807) Optimize selfdestruct opcode in LegacyVM by reducing state accesses in certain out-of-gas scenarios.
- Changed: [#5806](https://github.com/ethereum/aleth/pull/5806) Optimize selfdestruct opcode in aleth-interpreter by reducing state accesses in certain out-of-gas scenarios.
- Changed: [#5837](https://github.com/ethereum/aleth/pull/5837) [#5839](https://github.com/ethereum/aleth/pull/5839) [#5845](https://github.com/ethereum/aleth/pull/5845) [#5846](https://github.com/ethereum/aleth/pull/5846) Output format of `testeth --jsontrace` command changed to better match output of geth's evm tool and to integrate with evmlab project.
- Changed: [#5848](https://github.com/ethereum/aleth/pull/5848) `aleth-vm --codefile <PATH>` now reads bytecode file from path and `aleth-vm --codefile - <bytecode>` now reads bytecode from standard input.
- Removed: [#5760](https://github.com/ethereum/aleth/pull/5760) Official support for Visual Studio 2015 has been dropped. Compilation with this compiler is expected to stop working after migration to C++14.
- Removed: [#5840](https://github.com/ethereum/aleth/pull/5840) The list of precompiled contracts is not required in config files anymore.
- Removed: [#5850](https://github.com/ethereum/aleth/pull/5850) accounts section is now optional in config files.
Expand Down
54 changes: 30 additions & 24 deletions aleth-vm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LastBlockHashes : public eth::LastBlockHashesFace
int main(int argc, char** argv)
{
setDefaultOrCLocale();
string inputFile;
string codeFile;
Mode mode = Mode::Statistics;
State state(0);
Address sender = Address(69);
Expand All @@ -89,7 +89,7 @@ int main(int argc, char** argv)
blockHeader.setGasLimit(maxBlockGasLimit());
blockHeader.setTimestamp(0);
bytes data;
bytes code;
string code;

Ethash::init();
NoProof::init();
Expand All @@ -113,6 +113,8 @@ int main(int argc, char** argv)
addTransactionOption("input", po::value<string>(), "<d> Transaction code should be <d>");
addTransactionOption("code", po::value<string>(),
"<d> Contract code <d>. Makes transaction a call to this contract");
addTransactionOption("codefile", po::value<string>(),
"<path> File containing contract code. If '-' is specified, code is read from stdin");

po::options_description networkOptions("Network options", c_lineWidth);
networkOptions.add_options()("network", po::value<string>(),
Expand Down Expand Up @@ -145,8 +147,7 @@ int main(int argc, char** argv)
->notifier([&](int64_t _t) { blockHeader.setTimestamp(_t); }),
"<n> Set timestamp");

po::options_description allowedOptions(
"Usage ethvm <options> [trace|stats|output|test] (<file>|-)");
po::options_description allowedOptions("Usage ethvm <options> [trace|stats|output|test]");
allowedOptions.add(vmProgramOptions(c_lineWidth))
.add(networkOptions)
.add(optionsForTrace)
Expand Down Expand Up @@ -174,8 +175,6 @@ int main(int argc, char** argv)
mode = Mode::Trace;
else if (arg == "test")
mode = Mode::Test;
else if (inputFile.empty())
inputFile = arg; // Assign input file name only once.
else
{
cerr << "Unknown argument: " << arg << '\n';
Expand Down Expand Up @@ -239,29 +238,24 @@ int main(int argc, char** argv)
if (vm.count("input"))
data = fromHex(vm["input"].as<string>());
if (vm.count("code"))
code = fromHex(vm["code"].as<string>());
code = vm["code"].as<string>();
if (vm.count("codefile"))
codeFile = vm["codefile"].as<string>();

// Read code from input file.
if (!inputFile.empty())
if (!codeFile.empty())
{
if (!code.empty())
cerr << "--code argument overwritten by input file " << inputFile << '\n';

if (inputFile == "-")
for (int i = cin.get(); i != -1; i = cin.get())
code.push_back(static_cast<byte>(i));
else
code = contents(inputFile);

try // Try decoding from hex.
{
std::string strCode{reinterpret_cast<char const*>(code.data()), code.size()};
strCode.erase(strCode.find_last_not_of(" \t\n\r") + 1); // Right trim.
code = fromHex(strCode, WhenError::Throw);
cerr << "Options --code and --codefile shouldn't be used at the same time" << '\n';
return AlethErrors::ArgumentProcessingFailure;
}
catch (BadHexCharacter const&)
{
} // Ignore decoding errors.

if (codeFile == "-")
std::getline(std::cin, code);
else
code = contentsString(codeFile);
code.erase(code.find_last_not_of(" \t\n\r") + 1); // Right trim.
}

unique_ptr<SealEngineFace> se(ChainParams(genesisInfo(networkName)).createSealEngine());
Expand All @@ -275,7 +269,19 @@ int main(int argc, char** argv)
// Deploy the code on some fake account to be called later.
Account account(0, 0);
auto const latestVersion = se->evmSchedule(envInfo.number()).accountVersion;
account.setCode(bytes{code}, latestVersion);

bytes codeBytes;
try
{
codeBytes = fromHex(code, WhenError::Throw);
}
catch (BadHexCharacter const&)
{
cerr << "Provided code contains invalid characters.\n";
return AlethErrors::ArgumentProcessingFailure;
}

account.setCode(bytes{codeBytes}, latestVersion);
std::unordered_map<Address, Account> map;
map[contractDestination] = account;
state.populateFrom(map);
Expand Down

0 comments on commit 1614343

Please sign in to comment.