Conversation
|
The diff is kind of pointless here as the target has diverted from |
|
@goodlyrottenapple The actual patch starts on commit fa1e9a5. Each precompile refactor has its own commit, so it is probably best reviewed on a commit-by-commit basis. (the base of this patch is #2090) |
|
Might it be worth rolling most of the new enum class PrecompileImplOpts
{
FreeOnNull,
SuccessOnNull,
};
template <typename>
struct impl_out_size;
template <size_t N>
struct impl_out_size<
PrecompileImplResult (*)(byte_string_view, std::span<uint8_t, N>)>
{
static constexpr size_t value = N;
};
template <auto Impl, PrecompileImplOpts... Opts>
static PrecompileResult alloc_and_execute(byte_string_view const input)
{
constexpr bool free_on_null =
((Opts == PrecompileImplOpts::FreeOnNull) || ...);
constexpr bool success_on_null =
((Opts == PrecompileImplOpts::SuccessOnNull) || ...);
constexpr size_t N = impl_out_size<decltype(Impl)>::value;
auto *const out = static_cast<uint8_t *>(std::malloc(N));
MONAD_ASSERT(out != nullptr);
auto const result = Impl(input, std::span<uint8_t, N>{out, N});
if (result.data == nullptr) {
MONAD_DEBUG_ASSERT(result.size == 0);
if constexpr (free_on_null) {
std::free(out);
}
if constexpr (success_on_null) {
return {EVMC_SUCCESS, nullptr, 0};
}
return PrecompileResult::failure();
}
return {EVMC_SUCCESS, result.data, result.size};
}then in cases, have e.g.: CASE(0x02, sha256_gas_cost, alloc_and_execute<sha256_impl>);
...
CASE(
0x09, blake2bf_gas_cost<traits>,
alloc_and_execute<blake2bf_impl, PrecompileImplOpts::FreeOnNull>);
...
CASE(
0x0100, p256_verify_gas_cost,
alloc_and_execute<
p256_verify_impl, PrecompileImplOpts::FreeOnNull,
PrecompileImplOpts::SuccessOnNull>
... |
Yes. I think this might be a good way to cut down the boilerplate. I will look into this. |
1f1a96f to
3b6ec81
Compare
|
I dug more into the precompiles I hadn't looked at yet, and I think that template generic'ing is actually premature here. I think there are more opportunities to follow the pattern in In light of that I'm just cleaning up the commits and rebasing my other changes and then I would be good with the commit. |
1165e25 to
d6bd1b8
Compare
Add a standalone CMake project (category/zkvm/) that builds libmonad-zkvm.a for bare-metal RISC-V targets (ZisK and SP1 zkVM backends). This allows the Monad EVM interpreter to run inside zkVMs. Key changes: - RISC-V toolchain file (rv64ima, lp64, medany, -nostdlib++) - intx-backed uint256 wrapper replacing AVX2 implementation - zkVM-abstracted allocator (zkvm_aligned_alloc) and exit (zkvm_exit) interfaces with ZisK/SP1 backends - Conditional compilation guards (#ifdef MONAD_ZKVM) for bare-metal compatibility across interpreter, runtime, and core components - Shared compile_options.cmake extracted from root CMakeLists.txt - Bare-metal stubs: libc (malloc/calloc/free), libstdc++ (operator new/delete, std::terminate), and assert handlers Co-Authored-By: Claude Opus 4.6 <[email protected]>
…vm/src/precompiles_impl.cpp
d6bd1b8 to
c7228b5
Compare
No description provided.