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

C API level 0: core execution #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

C API level 0: core execution #1

wants to merge 1 commit into from

Conversation

chfast
Copy link
Member

@chfast chfast commented Jun 23, 2022

This is proof-of-concept of C API level 0 for Ethereum precompiles.

The level 0 expose core execution functionality of a precompile using common function signature.
The function receives input and output byte buffers.
It returns a pair: error code and number of bytes written to the output buffer (output size).

The user of the API must compute the gas cost and the maximum output size on its own.


SilkpreResult ethprecompiled_expmod(const uint8_t* input, size_t input_size, uint8_t* output, size_t output_size) {
const auto r = silkpre_expmod_run(input, input_size);
assert(output_size == r.size);
Copy link
Member Author

Choose a reason for hiding this comment

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

We are debating how to handle the case where user provides output buffer not big enough to handle the output produced by the library. This situation is programmer error caused by incorrectly computing the max output size and must be fixed in code. Reasonable handling is to abort/panic the process.

  1. The output_size parameter may be removed and library should assume the buffer is big enough. Related error can only be detected by crashes or ASan tools. This is also not compatible with Rust from_raw_parts().
  2. The library aborts execution with some log.
  3. The library reports the special error code which must be handled differently than EVM exceptions. The client does not have much options than abort in this case.

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.

1 participant