Skip to content

Commit

Permalink
Add point evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Sep 26, 2024
1 parent e40bd1a commit 20eb80c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,8 @@ libbitcoin_common_a_SOURCES = \
eth_client/libdevcrypto/Hash.h \
eth_client/libdevcrypto/LibSnark.cpp \
eth_client/libdevcrypto/LibSnark.h \
eth_client/libdevcrypto/LibKzg.cpp \
eth_client/libdevcrypto/LibKzg.h \
eth_client/libethashseal/GenesisInfo.cpp \
eth_client/libethashseal/GenesisInfo.h \
eth_client/libethashseal/genesis/qtumNetwork.cpp \
Expand Down
31 changes: 31 additions & 0 deletions src/eth_client/libdevcrypto/LibKzg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <libdevcrypto/LibKzg.h>
#include <evmone_precompiles/kzg.hpp>

using namespace std;
using namespace dev;
using namespace dev::crypto;

pair<bool, bytes> dev::crypto::point_evaluation_execute(dev::bytesConstRef input)
{
bytes output(64, 0);
size_t output_size = output.size();
size_t input_size = input.size();
assert(output_size >= 64);
if (input_size != 192)
return {false, bytes{}};

const auto r = evmone::crypto::kzg_verify_proof(reinterpret_cast<const std::byte*>(&input[0]),
reinterpret_cast<const std::byte*>(&input[32]),
reinterpret_cast<const std::byte*>(&input[64]),
reinterpret_cast<const std::byte*>(&input[96]),
reinterpret_cast<const std::byte*>(&input[96 + 48]));

if (!r)
return {false, bytes{}};

// Return FIELD_ELEMENTS_PER_BLOB and BLS_MODULUS as padded 32 byte big endian values
// as required by the EIP-4844.
intx::be::unsafe::store(output.data(), evmone::crypto::FIELD_ELEMENTS_PER_BLOB);
intx::be::unsafe::store(output.data() + 32, evmone::crypto::BLS_MODULUS);
return {true, output};
}
13 changes: 13 additions & 0 deletions src/eth_client/libdevcrypto/LibKzg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <libdevcore/Common.h>

namespace dev
{
namespace crypto
{

std::pair<bool, bytes> point_evaluation_execute(bytesConstRef _in);

}
}
12 changes: 12 additions & 0 deletions src/eth_client/libethcore/Precompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <libdevcrypto/Common.h>
#include <libdevcrypto/Hash.h>
#include <libdevcrypto/LibSnark.h>
#include <libdevcrypto/LibKzg.h>
#include <libethcore/Common.h>
#include <qtum/qtumutils.h>
using namespace std;
Expand Down Expand Up @@ -320,4 +321,15 @@ ETH_REGISTER_PRECOMPILED_PRICER(blake2_compression)
auto const rounds = fromBigEndian<uint32_t>(_in.cropped(0, 4));
return rounds;
}

ETH_REGISTER_PRECOMPILED_PRICER(point_evaluation)
(bytesConstRef /*_in*/, ChainOperationParams const& /*_chainParams*/, u256 const& /*_blockNumber*/)
{
return 50000;
}

ETH_REGISTER_PRECOMPILED(point_evaluation)(bytesConstRef _in)
{
return dev::crypto::point_evaluation_execute(_in);
}
}
2 changes: 2 additions & 0 deletions src/eth_client/libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ void ChainParams::loadConfig(
{Address{0x8}, PrecompiledContract{"alt_bn128_pairing_product", byzantiumForkBlock}});
precompiled.insert(
{Address{0x9}, PrecompiledContract{"blake2_compression", istanbulForkBlock}});
precompiled.insert(
{Address{0xa}, PrecompiledContract{"point_evaluation", cancunForkBlock}});
precompiled.insert({Address{0x85}, PrecompiledContract{"btc_ecrecover", qip6ForkBlock}});

stateRoot = _stateRoot ? _stateRoot : calculateStateRoot(true);
Expand Down

0 comments on commit 20eb80c

Please sign in to comment.