-
Notifications
You must be signed in to change notification settings - Fork 315
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
precompiles: Optionally use silkpre as implementation #660
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
809bdb4
cmake: Optionally fetch silkpre library
chfast 548ec92
precompiles: Optionally use silkpre as implementation
chfast c50f3df
precompiles: Add one more blake2b stub entry
chfast cf5e881
ci: Test silkpre precompiles
chfast 3f06da2
readme: Add section about precompiles support
chfast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2022 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "precompiles_silkpre.hpp" | ||
#include <silkpre/precompile.h> | ||
#include <cassert> | ||
#include <cstring> | ||
|
||
namespace evmone::state | ||
{ | ||
namespace | ||
{ | ||
ExecutionResult execute(const uint8_t* input, size_t input_size, uint8_t* output_buf, | ||
[[maybe_unused]] size_t max_output_size, PrecompileId id) noexcept | ||
{ | ||
const auto index = stdx::to_underlying(id) - 1; | ||
const auto [output, output_size] = kSilkpreContracts[index].run(input, input_size); | ||
if (output == nullptr) | ||
return {EVMC_PRECOMPILE_FAILURE, 0}; | ||
|
||
// Check if max_output_size computed by analysis match the computed result. | ||
assert(output_size <= max_output_size); | ||
chfast marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const auto trimmed_output_size = std::min(output_size, max_output_size); | ||
std::memcpy(output_buf, output, trimmed_output_size); | ||
std::free(output); // Free output allocation (required by silkpre API). | ||
return {EVMC_SUCCESS, trimmed_output_size}; | ||
} | ||
} // namespace | ||
|
||
ExecutionResult silkpre_ecrecover_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::ecrecover); | ||
} | ||
|
||
ExecutionResult silkpre_sha256_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::sha256); | ||
} | ||
|
||
ExecutionResult silkpre_ripemd160_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::ripemd160); | ||
} | ||
|
||
ExecutionResult silkpre_expmod_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::expmod); | ||
} | ||
|
||
ExecutionResult silkpre_ecadd_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::ecadd); | ||
} | ||
|
||
ExecutionResult silkpre_ecmul_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::ecmul); | ||
} | ||
|
||
|
||
ExecutionResult silkpre_ecpairing_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::ecpairing); | ||
} | ||
|
||
ExecutionResult silkpre_blake2bf_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept | ||
{ | ||
return execute(input, input_size, output_buf, max_output_size, PrecompileId::blake2bf); | ||
} | ||
} // namespace evmone::state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// evmone: Fast Ethereum Virtual Machine implementation | ||
// Copyright 2022 The evmone Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
#pragma once | ||
|
||
#include "precompiles.hpp" | ||
|
||
namespace evmone::state | ||
{ | ||
ExecutionResult silkpre_ecrecover_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_sha256_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_ripemd160_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_expmod_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_ecadd_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_ecmul_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_ecpairing_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
|
||
ExecutionResult silkpre_blake2bf_execute( | ||
const uint8_t* input, size_t input_size, uint8_t* output_buf, size_t max_output_size) noexcept; | ||
} // namespace evmone::state |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
#ifdef
with two branches directly in the initialization above ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is structured as optional override. It also allows us quickly change what we override with silkpre.