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

Reorder status codes #23

Merged
merged 1 commit into from
Apr 23, 2018
Merged

Reorder status codes #23

merged 1 commit into from
Apr 23, 2018

Conversation

chfast
Copy link
Member

@chfast chfast commented Apr 18, 2018

Fixes #21.

@chfast chfast requested review from axic and ehildenb and removed request for axic April 18, 2018 14:08
ehildenb
ehildenb previously approved these changes Apr 18, 2018
Copy link

@ehildenb ehildenb left a comment

Choose a reason for hiding this comment

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

Looks good, I think the new order makes more sense.

include/evmc.h Outdated
* Tried to read outside memory bounds.
*
* An example is RETURNDATACOPY reading past the available buffer.
*/
EVMC_INVALID_MEMORY_ACCESS = 10,
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 this should come before static mode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

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 a logical order would be:

  • invalid/unknown instructions
  • invalid number of arguments for instructions
  • invalid arguments (bad jump, invalid memory access)
  • invalid state (static mode violation)

Copy link
Member

Choose a reason for hiding this comment

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

No comment on this nice ordered list? 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

I did it this way...

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so :)

Copy link
Member Author

Choose a reason for hiding this comment

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

EVMC_INVALID_MEMORY_ACCESS = 9,
EVMC_CALL_DEPTH_EXCEDED = 10,
EVMC_STATIC_MODE_VIOLATION = 11,

What am I missing?

Copy link
Member

Choose a reason for hiding this comment

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

This part:

  • invalid/unknown instructions
  • invalid number of arguments for instructions
  • invalid arguments (bad jump)

The order now is argument count, bad jump, invalid/unknown, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Reordered again then.

include/evmc.h Outdated
* Successful execution is represented by ::EVMC_SUCCESS having value 0.
* Positive values represent failures defined by VM specifications with generic
* ::EVMC_FAILURE code of value 1.
* Negative values represent VM internal errors and might be not recoverable.
Copy link
Member

Choose a reason for hiding this comment

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

Should mention the special REJECTED here I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Mentioned.

include/evmc.h Outdated
* For example, the Client tries running a code in the EVM 1.5. If the
* code is not supported there, the execution falls back to the EVM 1.0.
*/
EVMC_REJECTED = -2,
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for swapping these two?

Copy link
Member Author

Choose a reason for hiding this comment

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

The generic first, the specific after.

Copy link
Member

Choose a reason for hiding this comment

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

I a bit torn on this, since REJECTED is a special one and I am not sure it is an internal error. It is certainly recoverable.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's internal in sense it should not be passed back to the caller.
Yes, it's recoverable if the client supports it and has a backup VM. I will extend the description of evmc_status_code to mention this as suggested.

include/evmc.h Outdated
* (see e.g. ::EVMC_REJECTED), otherwise internal errors are not recoverable.
* The generic representant of errors is ::EVMC_INTERNAL_ERROR but
* an EVM implementation MAY return negative status codes that are not defined
* in the EVMC documentation.
Copy link
Member

Choose a reason for hiding this comment

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

Should probably leave a comment here along the lines of "should you need more error codes, please create an issue on the evmc repo to discuss" to facilitate discussion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

@chfast chfast force-pushed the status-codes-reorder branch 3 times, most recently from 750b35b to 69ba561 Compare April 19, 2018 13:16
@ehildenb
Copy link

I might be good to start a convention along the lines of:

  • 0*: normal statuses (EVMC_SUCCESS, EVMC_REVERT, etc ...)
  • 1*: exceptional statuses (oog, oom, etc...)
  • 2*: validity statuses (bad jump structure, etc ...)
  • 3*: error modes (internal error, etc ...)

this way we don't have to re-organize the entire error-code space every time we add codes. Perhaps we make them hexadecimal numbers to allow for at least 16 codes in each category.

Notice that the KEVM formalization of this: https://github.com/kframework/evm-semantics/blob/typed-exceptions/network.md
does not include numbers, it simply bins them by sort. So I have a sort ExceptionalStatusCode for execeptions, and EndStatusCode for ones that end execution, then just "the rest". Also note that I have EVMC_BALANCE_UNDERFLOW and EVMC_ACCOUNT_ALREADY_EXISTS as status codes which are not present here (and are used in KEVM).

@chfast
Copy link
Member Author

chfast commented Apr 19, 2018

I don't mind categories, but I'm capable of doing good clusterization myself. If that will follow external reference I'm ok if having this here.

Personally, I believe it will just look nice here, with not benefits for implementations.

I'd like to keep internal errors with negative values. This way you can specify that status_code >= 0 must be passed to the caller and status_code < 0 must not be passed to the caller.

I would also avoid hex, because the number would like different in this header (e.g. 0x11) and different in logs (e.g. Failure code 17) so you cannot quickly look them up here.
If we need more space than 10, use 100.

What do you think @axic?

@axic
Copy link
Member

axic commented Apr 20, 2018

I would also avoid hex, because the number would like different in this header (e.g. 0x11) and different in logs (e.g. Failure code 17) so you cannot quickly look them up here.

This seems to be a reasonable idea.

I wouldn't bother too much about this, I think 0.2.0 will come soon after all these different implementers experience the first problems and we can fix it there.

@chfast
Copy link
Member Author

chfast commented Apr 20, 2018

I wouldn't bother too much about this, I think 0.2.0 will come soon after all these different implementers experience the first problems and we can fix it there.

I'm a bit inclined not to overdesign it now.

EVMC_INVALID_MEMORY_ACCESS = 9,

/** Call depth has exceeded the limit (if any) */
EVMC_CALL_DEPTH_EXCEDED = 10,
Copy link
Member

Choose a reason for hiding this comment

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

This still has the typo (exceded vs. exceeded).

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I only fixed the comment.

@chfast chfast force-pushed the status-codes-reorder branch from 69ba561 to a66a89e Compare April 20, 2018 22:38
@chfast chfast force-pushed the status-codes-reorder branch from a66a89e to 9938b3b Compare April 21, 2018 22:14

/**
* The execution has attempted to put more items on the EVM stack
* than the specified limit.
Copy link

@timxor timxor Apr 22, 2018

Choose a reason for hiding this comment

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

Was the EVM stack limit 1024? If it is not going to change in the future, then it may be of use to include that number here (in the comments) 😁 @chfast

Copy link
Member Author

Choose a reason for hiding this comment

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

Both limits for stack and call depth are 1024 and have never changed.

Copy link
Member

Choose a reason for hiding this comment

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

It may make sense including in the description but not in the error name. We can consider it when a hardfork is introduced changing those :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I will leave it for another time...

*/
EVMC_INVALID_MEMORY_ACCESS = 9,

/** Call depth has exceeded the limit (if any) */
Copy link

Choose a reason for hiding this comment

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

Was the call depth limit, also 1024?

Copy link

@timxor timxor left a comment

Choose a reason for hiding this comment

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

English looks good to me!

* For example, the Client tries running a code in the EVM 1.5. If the
* code is not supported there, the execution falls back to the EVM 1.0.
*/
EVMC_REJECTED = -2,
Copy link

Choose a reason for hiding this comment

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

In my opinion (for what it is worth) a more descriptive name would be EVMC_INCOMPATIBILE_VERSION or EVMC_INVALID_VERSION

Copy link
Member Author

Choose a reason for hiding this comment

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

The provided example is not the only case we are using it even now. You can configure EVMJIT to jit only popular codes (measured by hit count). It will return EVMC_REJECTED if the hit count for requested code is below the threshold.

@chfast chfast merged commit 766d4ab into master Apr 23, 2018
@chfast chfast deleted the status-codes-reorder branch April 23, 2018 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants