Skip to content

Commit

Permalink
Merge pull request #2928 from Taraxa-project/cornus-hf
Browse files Browse the repository at this point in the history
Cornus hf
  • Loading branch information
MatusKysel authored Jan 9, 2025
2 parents 3eacb02 + 33cc047 commit b628300
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ set(LLVM_VERSION "17")
include(CMakeModules/clang_tidy.cmake)

# clang-format
include(CMakeModules/clang_format.cmake)
# include(CMakeModules/clang_format.cmake)

# cppcheck
include(CMakeModules/cppcheck.cmake)
Expand Down
8 changes: 6 additions & 2 deletions doc/evm_incompatibilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ Following EIPs are not supported by our EVM:
- [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844)
- [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718)


## Latest supported solc version
We currently support `0.8.26`.

## go-ethereum library
If you are having issue with go-ethereum library, please use our slightly modified version https://github.com/Taraxa-project/go-ethereum
If you are having issue with go-ethereum library, please use our slightly modified version https://github.com/Taraxa-project/go-ethereum

# Nonce handling
Due to nature of DAG which can reorder transactions:
- Nonce skipping is possible meaning any transaction with nonce larger than previous nonce can be executed.
- It is possible for a transaction without enough balance to pay gas to reach EVM and execution. These transactions will increase the account nonce.
4 changes: 4 additions & 0 deletions libraries/aleth/libp2p/NodeTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ bool NodeTable::addNode(Node const& _node) {
auto const it = m_allNodes.find(_node.id);
needToPing = (it == m_allNodes.end() || it->second->endpoint() != _node.get_endpoint() ||
!it->second->hasValidEndpointProof());
if (needToPing && it != m_allNodes.end() &&
it->second->lastPongReceivedTime > RLPXDatagramFace::secondsSinceEpoch() - m_requestTimeToLive.count()) {
needToPing = false;
}
}

if (needToPing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,7 @@
},
"sortition": {
"changes_count_for_average": 10,
"dag_efficiency_targets": [
4900,
5100
],
"dag_efficiency_targets": [4900, 5100],
"changing_interval": 200,
"computation_interval": 50,
"vrf": {
Expand Down Expand Up @@ -286,10 +283,10 @@
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
},
"cornus_hf": {
"block_num": 0,
"block_num": 1000,
"delegation_locking_period": 5,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@
"bridge_contract_address": "0xe126E0BaeAE904b8Cfd619Be1A8667A173b763a1"
},
"cornus_hf": {
"block_num": -1,
"block_num": 15610000,
"delegation_locking_period": 163459,
"dag_gas_limit": "0x1908B100",
"pbft_gas_limit": "0x7d2b7500"
Expand Down
5 changes: 5 additions & 0 deletions libraries/common/include/common/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const size_t kV3NetworkVersion = 3;

const uint32_t kRecentlyFinalizedTransactionsFactor = 2;

constexpr uint64_t kTxGas = 21000;
constexpr uint64_t kTxGasContractCreation = 53000;
constexpr uint64_t kTxDataZeroGas = 4;
constexpr uint64_t kTxDataNonZeroGas = 68;

// The various denominations; here for ease of use where needed within code.
static const u256 kOneTara = dev::exp10<18>();
// static const u256 kFinney = exp10<15>();
Expand Down
2 changes: 1 addition & 1 deletion libraries/core_libs/consensus/src/pbft/pbft_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ void PbftManager::gossipVote(const std::shared_ptr<PbftVote> &vote, const std::s
auto net = network_.lock();
if (!net) {
LOG(log_er_) << "Could not obtain net - cannot gossip new vote";
assert(false);
// assert(false);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ std::pair<bool, std::string> TransactionManager::verifyTransaction(const std::sh
return {false, "invalid gas"};
}

if (kConf.genesis.state.hardforks.isOnCornusHardfork(this->final_chain_->lastBlockNumber())) {
if (!trx->intrinsicGasCovered()) {
return {false, "intrinsic gas too low"};
}
}

try {
trx->getSender();
} catch (Transaction::InvalidSignature const &) {
Expand All @@ -73,6 +79,7 @@ std::pair<bool, std::string> TransactionManager::verifyTransaction(const std::sh
return {false, "gas_price too low"};
}


return {true, ""};
}

Expand Down
2 changes: 2 additions & 0 deletions libraries/core_libs/network/rpc/jsonrpc_ws_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ std::string JsonRpcWsSession::handleSubscription(const Json::Value &req) {
if (params.size() == 2 && params[1].asString() == "includeSignatures") {
include_pillar_block_signatures = true;
}
} else {
throw std::runtime_error("Invalid subscription type");
}
}

Expand Down
28 changes: 28 additions & 0 deletions libraries/core_libs/storage/include/storage/problematic_trx.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <libdevcore/CommonJS.h>

#include "transaction/transaction.hpp"

namespace taraxa {

//{
// "blockHash":"0x6722e9c012f783c3d42e0e920b3c446f6c14273662eb063a794b1718da632a42",
// "blockNumber":"0xb31684",
// "from":"0xde2b1203d72d3549ee2f733b00b2789414c7cea5",
// "gas":"0x0",
// "gasPrice":"0x1",
// "hash":"0xdf374602b4f698a5ec6c8b2a9c27ac1b3190c093cd4ab5e624fe21caca6c24a1",
// "input":"0x",
// "nonce":"0x0",
// "r":"0xb48d8b4b64040e4bd585bf638a74a355be589251dc7458c0e5e563e7fe0d630a",
// "s":"0x57726ccf2fd4e97b297a212ed1f82beedd3c7b7326d07e12e50c87b331c60500",
// "to":"0x973ecb1c08c8eb5a7eaa0d3fd3aab7924f2838b0",
// "transactionIndex":"0x6",
// "v":"0x1",
// "value":"0x0"
//}
const static auto kProblematicTrx = std::make_shared<Transaction>(dev::jsToBytes(
"0xf85f80018094973ecb1c08c8eb5a7eaa0d3fd3aab7924f2838b080808206b6a0b48d8b4b64040e4bd585bf638a74a355be589251dc7458c0"
"e5e563e7fe0d630aa057726ccf2fd4e97b297a212ed1f82beedd3c7b7326d07e12e50c87b331c60500"));
} // namespace taraxa
7 changes: 6 additions & 1 deletion libraries/core_libs/storage/src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "final_chain/data.hpp"
#include "pillar_chain/pillar_block.hpp"
#include "rocksdb/utilities/checkpoint.h"
#include "storage/uint_comparator.hpp"
#include "storage/problematic_trx.hpp"
#include "transaction/system_transaction.hpp"
#include "vote/pbft_vote.hpp"
#include "vote/votes_bundle_rlp.hpp"
Expand Down Expand Up @@ -885,6 +885,11 @@ SharedTransactions DbStorage::getFinalizedTransactions(std::vector<trx_hash_t> c
std::map<PbftPeriod, std::set<uint32_t>> period_map;
trxs.reserve(trx_hashes.size());
for (auto const& tx_hash : trx_hashes) {
// TODO remove after Cornus HF
if (tx_hash == kProblematicTrx->getHash()) {
trxs.emplace_back(kProblematicTrx);
continue;
}
auto trx_period = getTransactionLocation(tx_hash);
if (trx_period.has_value()) {
period_map[trx_period->period].insert(trx_period->position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct Transaction {
explicit Transaction(const bytes &_rlp, bool verify_strict = false, const h256 &hash = {});
virtual ~Transaction() = default;

bool intrinsicGasCovered() const;
auto isZero() const { return is_zero_; }
const trx_hash_t &getHash() const;
auto getNonce() const { return nonce_; }
Expand Down Expand Up @@ -85,6 +86,7 @@ using Transactions = std::vector<Transaction>;
using SharedTransactions = std::vector<SharedTransaction>;
using TransactionHashes = std::vector<trx_hash_t>;

uint64_t IntrinsicGas(const std::vector<uint8_t> &data, bool is_contract_creation);
TransactionHashes hashes_from_transactions(const SharedTransactions &transactions);

} // namespace taraxa
37 changes: 37 additions & 0 deletions libraries/types/transaction/src/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <utility>

#include "common/constants.hpp"
#include "common/encoding_rlp.hpp"

namespace taraxa {
Expand Down Expand Up @@ -178,4 +179,40 @@ void Transaction::rlp(::taraxa::util::RLPDecoderRef encoding) { fromRLP(encoding

void Transaction::rlp(::taraxa::util::RLPEncoderRef encoding) const { encoding.appendRaw(rlp()); }

inline uint64_t IntrinsicGas(const std::vector<uint8_t> &data, bool is_contract_creation) {
uint64_t gas;
if (is_contract_creation) {
gas = kTxGasContractCreation;
} else {
gas = kTxGas;
}
// Bump the required gas by the amount of transactional data
if (!data.empty()) {
// Zero and non-zero bytes are priced differently
uint64_t nz = std::count_if(data.begin(), data.end(), [](uint8_t b) { return b != 0; });

// Make sure we don't exceed uint64 for all data combinations
if ((std::numeric_limits<uint64_t>::max() - gas) / kTxDataNonZeroGas < nz) {
throw std::runtime_error("Out of gas");
}
gas += nz * kTxDataNonZeroGas;

uint64_t z = static_cast<uint64_t>(data.size()) - nz;
if ((std::numeric_limits<uint64_t>::max() - gas) / kTxDataZeroGas < z) {
throw std::runtime_error("Out of gas");
}
gas += z * kTxDataZeroGas;
}
return gas;
}

bool Transaction::intrinsicGasCovered() const {
try {
uint64_t gas = IntrinsicGas(data_, !receiver_.has_value());
return gas <= gas_;
} catch (const std::runtime_error&) {
return false;
}
}

} // namespace taraxa
2 changes: 1 addition & 1 deletion submodules/taraxa-evm
Submodule taraxa-evm updated 1 files
+9 −0 core/vm/evm.go
11 changes: 11 additions & 0 deletions tests/transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,17 @@ TEST_F(TransactionTest, signature_performance) {
<< "ms" << std::endl;
}

TEST_F(TransactionTest, intrinsic_gas) {
EXPECT_EQ(IntrinsicGas(dev::bytes(), false), kTxGas);
EXPECT_EQ(IntrinsicGas(dev::bytes(), true), kTxGasContractCreation);
const auto data = dev::bytes(100000, 1);
EXPECT_EQ(IntrinsicGas(data, false), kTxGas + 100000 * kTxDataNonZeroGas);
EXPECT_EQ(IntrinsicGas(data, true), kTxGasContractCreation + 100000 * kTxDataNonZeroGas);
const auto data2 = dev::bytes(100000, 0);
EXPECT_EQ(IntrinsicGas(data2, false), kTxGas + 100000 * kTxDataZeroGas);
EXPECT_EQ(IntrinsicGas(data2, true), kTxGasContractCreation + 100000 * kTxDataZeroGas);
}

} // namespace taraxa::core_tests

using namespace taraxa;
Expand Down

0 comments on commit b628300

Please sign in to comment.