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

Adding "codeFile" parameter into aleth-vm options #5848

Merged
merged 5 commits into from
Nov 27, 2019

Conversation

josephnicholas
Copy link
Contributor

Changes:

  • Add --codeFile parameter and accept input file.
  • Modified the std implementation if --codeFile has -.

Open for reviews and modifications on this PR.

Part of #4613

@codecov-io
Copy link

codecov-io commented Nov 23, 2019

Codecov Report

Merging #5848 into master will decrease coverage by 0.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5848      +/-   ##
==========================================
- Coverage   64.07%   64.05%   -0.02%     
==========================================
  Files         362      362              
  Lines       30900    30912      +12     
  Branches     3432     3433       +1     
==========================================
+ Hits        19800    19802       +2     
- Misses       9874     9881       +7     
- Partials     1226     1229       +3

aleth-vm/main.cpp Outdated Show resolved Hide resolved
aleth-vm/main.cpp Outdated Show resolved Hide resolved
aleth-vm/main.cpp Outdated Show resolved Hide resolved
{
if (!code.empty())
cerr << "--code argument overwritten by input file " << inputFile << '\n';
cerr << "--code argument overwritten by input file " << codeFile << '\n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please better in case both --code and --codefile are present, output an error and exit.

Copy link
Contributor Author

@josephnicholas josephnicholas Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you need now to remove this if (!code.empty()) here, it will never be true

if (inputFile == "-")
for (int i = cin.get(); i != -1; i = cin.get())
code.push_back(static_cast<byte>(i));
string codeStr = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be simpler to use a single string variable instead of code and codeStr.

So try changing code to string, use it for getline and change line 255 to code = contentsString(codeFile).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this amendment will make the try/catch block unusable so I removed it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? We need that block, it decodes the hex string.

We should keep it, but it should decode the string that we have read either from file or from command line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gumb0 will do the changes, what you said totally make sense, I was really getting of myself, my apologies.

- change placeholder to <path>.
- use of single string for code.
- try catch removed since ::erase might not throw.
- add error message for using --code and --codefile at the same time.
@josephnicholas
Copy link
Contributor Author

@gumb0 after amendments from review. I got the output below. It seems to be different from what you mentioned on gitter.

$ ./aleth-vm --log-verbosity 4 --network Istanbul trace --flat --mnemonics --codefile code.hex 
{"depth":1,"gas":"9223372036854775807","gasCost":"2","memSize":0,"memory":[],"op":54,"opName":"CALLDATASIZE","pc":0,"stack":[],"storage":{}}
{"depth":1,"gas":"9223372036854775805","gasCost":"0","memSize":0,"memory":[],"op":0,"opName":"STOP","pc":1,"stack":["0x00"]}
DEBUG 11-26 10:57:32 aleth-vm overlaydb Closing state DB

@gumb0
Copy link
Member

gumb0 commented Nov 26, 2019

after amendments from review. I got the output below. It seems to be different from what you mentioned on gitter.

That's because now without hex decoding, the file is treated as binary, it tries to execute the opcode 54 which is the ascii code of the symbol 6

@josephnicholas
Copy link
Contributor Author

after amendments from review. I got the output below. It seems to be different from what you mentioned on gitter.

That's because now without hex decoding, the file is treated as binary, it tries to execute the opcode 54 which is the ascii code of the symbol 6

@gumb0 output code from code form latest changes.

➜  aleth-vm git:(aleth-vm-improvement) ✗ ./aleth-vm --log-verbosity 4 --network Istanbul trace --flat --mnemonics --codefile code.hex
{"depth":1,"gas":"9223372036854775807","gasCost":"3","memSize":0,"memory":[],"op":96,"opName":"PUSH1","pc":0,"stack":[],"storage":{}}
{"depth":1,"gas":"9223372036854775804","gasCost":"3","memSize":0,"memory":[],"op":96,"opName":"PUSH1","pc":2,"stack":["0x60"]}
{"depth":1,"gas":"9223372036854775801","gasCost":"3","memSize":0,"memory":[],"op":82,"opName":"MSTORE","pc":4,"stack":["0x60","0x00"]}
{"depth":1,"gas":"9223372036854775795","gasCost":"3","memSize":32,"memory":["0000000000000000000000000000000000000000000000000000000000000060"],"op":96,"opName":"PUSH1","pc":5,"stack":[]}
{"depth":1,"gas":"9223372036854775792","gasCost":"3","memSize":32,"memory":["0000000000000000000000000000000000000000000000000000000000000060"],"op":96,"opName":"PUSH1","pc":7,"stack":["0x20"]}
{"depth":1,"gas":"9223372036854775789","gasCost":"0","memSize":32,"memory":["0000000000000000000000000000000000000000000000000000000000000060"],"op":243,"opName":"RETURN","pc":9,"stack":["0x20","0x00"]}
DEBUG 11-27 19:20:44      overlaydb Closing state DB

Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could you please add a entry to https://github.com/ethereum/aleth/blob/master/CHANGELOG.md describing how the command line changed

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);
code.erase(code.find_last_not_of(" \t\n\r") + 1); // Right trim.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently try/catch around this is useless (erase and code never throw), it was here to handle errors trown by fromHex.

It's fine that you moved fromHex into a single place for both --code and --codefile, but there needs to be hanlding of exceptions around it.

I guess you would need some new variable like bytes codeBytes and you would assign result fromHex to it inside try/catch, then pass codeBytes to setCode.

Also I find it strange that we ignored decoding errors before, so I'd say inside catch we should better output error and exit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gumb0 Changes pushed in the latest commit, please review if I understood your requirements perfectly. Thanks.

{
if (!code.empty())
cerr << "--code argument overwritten by input file " << inputFile << '\n';
if (vm.count("code"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be more efficient

Suggested change
if (vm.count("code"))
if (!code.empty())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gumb0 Added on latest commit.

@josephnicholas
Copy link
Contributor Author

Also could you please add a entry to https://github.com/ethereum/aleth/blob/master/CHANGELOG.md describing how the command line changed

Should this be changed on the same pull request?

@gumb0
Copy link
Member

gumb0 commented Nov 27, 2019

Should this be changed on the same pull request?

Yes, exactly

- Added changelog for added parameter change.
- Made some revisions based on review.
@josephnicholas
Copy link
Contributor Author

@gumb0 Thanks for correcting my changes, and thanks for the review.

@gumb0 gumb0 merged commit 1614343 into ethereum:master Nov 27, 2019
@gumb0
Copy link
Member

gumb0 commented Nov 27, 2019

@josephnicholas thank you for the contribution.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants