diff --git a/CMakeLists.txt b/CMakeLists.txt index b002b2844..354acc00b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,8 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_CXX_EXTENSIONS FALSE) +set(CMAKE_COLOR_DIAGNOSTICS TRUE) + #BEGIN internal option(BUILD_SHARED_LIBS "Use \"ON\" to build shared libraries instead of static where it's not specified (not recommended)" OFF) option(USE_EMSCRIPTEN "Use \"ON\" for config building wasm." OFF) diff --git a/blockchain-explorer/blockchain-explorer-http.cpp b/blockchain-explorer/blockchain-explorer-http.cpp index e5203cb7e..f07e0e9f4 100644 --- a/blockchain-explorer/blockchain-explorer-http.cpp +++ b/blockchain-explorer/blockchain-explorer-http.cpp @@ -366,7 +366,7 @@ HttpAnswer& HttpAnswer::operator<<(AccountCell acc_c) { last_trans_hash.set_zero(); block::CurrencyCollection balance = block::CurrencyCollection::zero(); try { - auto state_root = vm::MerkleProof::virtualize(acc_c.q_roots[1], 1); + auto state_root = vm::MerkleProof::virtualize(acc_c.q_roots[1]); if (state_root.is_null()) { abort("account state proof is invalid"); return *this; @@ -474,7 +474,7 @@ HttpAnswer& HttpAnswer::operator<<(BlockHeaderCell head_c) { vm::CellSlice cs{vm::NoVm(), head_c.root}; auto block_id = head_c.block_id; try { - auto virt_root = vm::MerkleProof::virtualize(head_c.root, 1); + auto virt_root = vm::MerkleProof::virtualize(head_c.root); if (virt_root.is_null()) { abort("invalid merkle proof"); return *this; diff --git a/crypto/CMakeLists.txt b/crypto/CMakeLists.txt index 79d1117ea..d9e2db4e2 100644 --- a/crypto/CMakeLists.txt +++ b/crypto/CMakeLists.txt @@ -78,7 +78,6 @@ set(TON_CRYPTO_CORE_SOURCE vm/cells/PrunnedCell.h vm/cells/UsageCell.h vm/cells/VirtualCell.h - vm/cells/VirtualizationParameters.h vm/cells.h vm/cellslice.h diff --git a/crypto/block/check-proof.cpp b/crypto/block/check-proof.cpp index 431a03fec..357d21fb0 100644 --- a/crypto/block/check-proof.cpp +++ b/crypto/block/check-proof.cpp @@ -73,7 +73,7 @@ td::Status check_block_header_proof(td::Ref root, ton::BlockIdExt blki td::Result check_state_proof(ton::BlockIdExt blkid, td::Slice proof) { TRY_RESULT(proof_root, vm::std_boc_deserialize(proof)); - auto virt_root = vm::MerkleProof::virtualize(std::move(proof_root), 1); + auto virt_root = vm::MerkleProof::virtualize(std::move(proof_root)); if (virt_root.is_null()) { return td::Status::Error("account state proof is invalid"); } @@ -86,7 +86,7 @@ td::Result> check_extract_state_proof(ton::BlockIdExt blkid, td::S try { TRY_RESULT(state_hash, check_state_proof(blkid, proof)); TRY_RESULT(state_root, vm::std_boc_deserialize(data)); - auto state_virt_root = vm::MerkleProof::virtualize(std::move(state_root), 1); + auto state_virt_root = vm::MerkleProof::virtualize(std::move(state_root)); if (state_virt_root.is_null()) { return td::Status::Error("account state proof is invalid"); } @@ -118,13 +118,13 @@ td::Status check_shard_proof(ton::BlockIdExt blk, ton::BlockIdExt shard_blk, td: return td::Status::Error("shard configuration proof must have exactly two roots"); } try { - auto mc_state_root = vm::MerkleProof::virtualize(std::move(P_roots[1]), 1); + auto mc_state_root = vm::MerkleProof::virtualize(std::move(P_roots[1])); if (mc_state_root.is_null()) { return td::Status::Error("shard configuration proof is invalid"); } ton::Bits256 mc_state_hash = mc_state_root->get_hash().bits(); TRY_STATUS_PREFIX( - check_block_header_proof(vm::MerkleProof::virtualize(std::move(P_roots[0]), 1), blk, &mc_state_hash, true), + check_block_header_proof(vm::MerkleProof::virtualize(std::move(P_roots[0])), blk, &mc_state_hash, true), "error in shard configuration block header proof :"); block::gen::ShardStateUnsplit::Record sstate; if (!(tlb::unpack_cell(mc_state_root, sstate))) { @@ -171,12 +171,12 @@ td::Status check_account_proof(td::Slice proof, ton::BlockIdExt shard_blk, const } try { - auto state_root = vm::MerkleProof::virtualize(std::move(Q_roots[1]), 1); + auto state_root = vm::MerkleProof::virtualize(std::move(Q_roots[1])); if (state_root.is_null()) { return td::Status::Error("account state proof is invalid"); } ton::Bits256 state_hash = state_root->get_hash().bits(); - TRY_STATUS_PREFIX(check_block_header_proof(vm::MerkleProof::virtualize(std::move(Q_roots[0]), 1), shard_blk, + TRY_STATUS_PREFIX(check_block_header_proof(vm::MerkleProof::virtualize(std::move(Q_roots[0])), shard_blk, &state_hash, true, save_utime, save_lt), "error in account shard block header proof : "); block::gen::ShardStateUnsplit::Record sstate; @@ -223,7 +223,7 @@ td::Result AccountState::validate(ton::BlockIdExt ref_blk, b Ref root; if (is_virtualized && true_root.not_null()) { - root = vm::MerkleProof::virtualize(true_root, 1); + root = vm::MerkleProof::virtualize(true_root); if (root.is_null()) { return td::Status::Error("account state proof is invalid"); } @@ -346,7 +346,7 @@ td::Result BlockTransactionList::validate(bool check if (check_proof) { try { TRY_RESULT(proof_cell, vm::std_boc_deserialize(std::move(proof_boc))); - auto virt_root = vm::MerkleProof::virtualize(proof_cell, 1); + auto virt_root = vm::MerkleProof::virtualize(proof_cell); if (blkid.root_hash != virt_root->get_hash().bits()) { return td::Status::Error("Invalid block proof root hash"); @@ -452,7 +452,7 @@ td::Status BlockProofLink::validate(td::uint32* save_utime) const { } try { // virtualize Merkle proof roots - auto vs_root = vm::MerkleProof::virtualize(proof, 1); + auto vs_root = vm::MerkleProof::virtualize(proof); if (vs_root.is_null()) { return td::Status::Error("BlockProofLink contains an invalid Merkle proof for source block "s + from.to_str()); } @@ -460,7 +460,7 @@ td::Status BlockProofLink::validate(td::uint32* save_utime) const { if (from.seqno()) { TRY_STATUS(check_block_header(vs_root, from, is_fwd ? nullptr : &state_hash)); } - auto vd_root = dest_proof.not_null() ? vm::MerkleProof::virtualize(dest_proof, 1) : Ref{}; + auto vd_root = dest_proof.not_null() ? vm::MerkleProof::virtualize(dest_proof) : Ref{}; if (vd_root.is_null() && to.seqno()) { return td::Status::Error("BlockProofLink contains an invalid Merkle proof for destination block "s + to.to_str()); } @@ -483,7 +483,7 @@ td::Status BlockProofLink::validate(td::uint32* save_utime) const { } if (!is_fwd) { // check a backward link - auto vstate_root = vm::MerkleProof::virtualize(state_proof, 1); + auto vstate_root = vm::MerkleProof::virtualize(state_proof); if (vstate_root.is_null()) { return td::Status::Error("backward BlockProofLink contains an invalid Merkle proof for source state "s + from.to_str()); diff --git a/crypto/test/test-db.cpp b/crypto/test/test-db.cpp index f4dde8df7..911f538a8 100644 --- a/crypto/test/test-db.cpp +++ b/crypto/test/test-db.cpp @@ -663,13 +663,13 @@ TEST(Cell, MerkleProof) { auto proof = MerkleProof::generate(cell, is_prunned); // CellBuilder::virtualize(proof, 1); //ASSERT_EQ(1u, proof->get_level()); - auto virtualized_proof = MerkleProof::virtualize(proof, 1); + auto virtualized_proof = MerkleProof::virtualize(proof); auto exploration3 = CellExplorer::explore(virtualized_proof, exploration.ops); ASSERT_EQ(exploration.log, exploration3.log); auto proof2 = MerkleProof::generate(cell, usage_tree.get()); CHECK(proof2->get_depth() == proof->get_depth()); - auto virtualized_proof2 = MerkleProof::virtualize(proof2, 1); + auto virtualized_proof2 = MerkleProof::virtualize(proof2); auto exploration4 = CellExplorer::explore(virtualized_proof2, exploration.ops); ASSERT_EQ(exploration.log, exploration4.log); } @@ -690,7 +690,7 @@ TEST(Cell, MerkleProofCombine) { CellExplorer::explore(usage_cell, exploration1.ops); proof1 = MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = MerkleProof::virtualize(proof1, 1); + auto virtualized_proof = MerkleProof::virtualize(proof1); auto exploration = CellExplorer::explore(virtualized_proof, exploration1.ops); ASSERT_EQ(exploration.log, exploration1.log); } @@ -702,7 +702,7 @@ TEST(Cell, MerkleProofCombine) { CellExplorer::explore(usage_cell, exploration2.ops); proof2 = MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = MerkleProof::virtualize(proof2, 1); + auto virtualized_proof = MerkleProof::virtualize(proof2); auto exploration = CellExplorer::explore(virtualized_proof, exploration2.ops); ASSERT_EQ(exploration.log, exploration2.log); } @@ -715,7 +715,7 @@ TEST(Cell, MerkleProofCombine) { CellExplorer::explore(usage_cell, exploration2.ops); proof12 = MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = MerkleProof::virtualize(proof12, 1); + auto virtualized_proof = MerkleProof::virtualize(proof12); auto exploration_a = CellExplorer::explore(virtualized_proof, exploration1.ops); auto exploration_b = CellExplorer::explore(virtualized_proof, exploration2.ops); ASSERT_EQ(exploration_a.log, exploration1.log); @@ -724,7 +724,7 @@ TEST(Cell, MerkleProofCombine) { { auto check = [&](auto proof_union) { - auto virtualized_proof = MerkleProof::virtualize(proof_union, 1); + auto virtualized_proof = MerkleProof::virtualize(proof_union); auto exploration_a = CellExplorer::explore(virtualized_proof, exploration1.ops); auto exploration_b = CellExplorer::explore(virtualized_proof, exploration2.ops); ASSERT_EQ(exploration_a.log, exploration1.log); @@ -738,14 +738,14 @@ TEST(Cell, MerkleProofCombine) { check(proof_union_fast); } { - cell = MerkleProof::virtualize(proof12, 1); + cell = MerkleProof::virtualize(proof12); auto usage_tree = std::make_shared(); auto usage_cell = UsageCell::create(cell, usage_tree->root_ptr()); CellExplorer::explore(usage_cell, exploration1.ops); auto proof = MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = MerkleProof::virtualize(proof, 2); + auto virtualized_proof = MerkleProof::virtualize(proof); auto exploration = CellExplorer::explore(virtualized_proof, exploration1.ops); ASSERT_EQ(exploration.log, exploration1.log); if (proof->get_hash() != proof1->get_hash()) { @@ -2152,28 +2152,28 @@ TEST(Cell, MerkleProofHands) { test_boc_deserializer_full(merkle_proof).ensure(); { - auto virtual_node = proof->virtualize({0, 1}); + auto virtual_node = proof->virtualize(0); ASSERT_EQ(0u, virtual_node->get_level()); - ASSERT_EQ(1u, virtual_node->get_virtualization()); + ASSERT_EQ(1u, virtual_node->is_virtualized()); CellSlice cs{NoVm(), virtual_node}; auto virtual_data = cs.fetch_ref(); ASSERT_EQ(0u, virtual_data->get_level()); - ASSERT_EQ(1u, virtual_data->get_virtualization()); + ASSERT_EQ(1u, virtual_data->is_virtualized()); ASSERT_EQ(data->get_hash(), virtual_data->get_hash()); auto virtual_node_copy = CellBuilder{}.store_bits(node->get_data(), node->get_bits()).store_ref(virtual_data).finalize(); ASSERT_EQ(0u, virtual_node_copy->get_level()); - ASSERT_EQ(1u, virtual_node_copy->get_virtualization()); + ASSERT_EQ(1u, virtual_node_copy->is_virtualized()); ASSERT_EQ(virtual_node->get_hash(), virtual_node_copy->get_hash()); { auto two_nodes = CellBuilder{}.store_ref(virtual_node).store_ref(node).finalize(); ASSERT_EQ(0u, two_nodes->get_level()); - ASSERT_EQ(1u, two_nodes->get_virtualization()); + ASSERT_EQ(1u, two_nodes->is_virtualized()); CellSlice cs2(NoVm(), two_nodes); - ASSERT_EQ(1u, cs2.prefetch_ref(0)->get_virtualization()); - ASSERT_EQ(0u, cs2.prefetch_ref(1)->get_virtualization()); + ASSERT_EQ(1u, cs2.prefetch_ref(0)->is_virtualized()); + ASSERT_EQ(0u, cs2.prefetch_ref(1)->is_virtualized()); } } LOG(ERROR) << td::NamedThreadSafeCounter::get_default(); @@ -2195,7 +2195,7 @@ TEST(Cell, MerkleProofArrayHands) { ASSERT_TRUE(proof->get_hash(1) != arr.root()->get_hash(1)); ASSERT_EQ(arr.root()->get_hash(0), arr.root()->get_hash(1)); - CompactArray new_arr(arr.size(), proof->virtualize({0, 1})); + CompactArray new_arr(arr.size(), proof->virtualize(0)); for (auto k : keys) { ASSERT_EQ(arr.get(k), new_arr.get(k)); } @@ -2222,7 +2222,7 @@ TEST(Cell, MerkleProofCombineArray) { } } - CompactArray arr2(n, vm::MerkleProof::virtualize(root, 1)); + CompactArray arr2(n, vm::MerkleProof::virtualize(root)); for (size_t i = 0; i < n; i++) { CHECK(arr.get(i) == arr2.get(i)); } @@ -2920,7 +2920,7 @@ TEST(TonDb, BocRespectsUsageCell) { auto usage_cell = vm::UsageCell::create(cell, usage_tree->root_ptr()); auto serialization = serialize_boc(usage_cell); auto proof = vm::MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = vm::MerkleProof::virtualize(proof, 1); + auto virtualized_proof = vm::MerkleProof::virtualize(proof); auto serialization_of_virtualized_cell = serialize_boc(virtualized_proof); ASSERT_STREQ(serialization, serialization_of_virtualized_cell); } @@ -2946,7 +2946,7 @@ TEST(UsageTree, ThreadSafe) { thread.join(); } auto proof = vm::MerkleProof::generate(cell, usage_tree.get()); - auto virtualized_proof = vm::MerkleProof::virtualize(proof, 1); + auto virtualized_proof = vm::MerkleProof::virtualize(proof); for (auto &exploration : explorations) { auto new_exploration = vm::CellExplorer::explore(virtualized_proof, exploration.ops); ASSERT_EQ(exploration.log, new_exploration.log); @@ -3024,8 +3024,8 @@ TEST(TonDb, DoNotMakeListsPrunned) { auto cell = vm::CellBuilder().store_bytes("abc").finalize(); auto is_prunned = [&](const td::Ref &cell) { return true; }; auto proof = vm::MerkleProof::generate(cell, is_prunned); - auto virtualized_proof = vm::MerkleProof::virtualize(proof, 1); - ASSERT_TRUE(virtualized_proof->get_virtualization() == 0); + auto virtualized_proof = vm::MerkleProof::virtualize(proof); + ASSERT_TRUE(!virtualized_proof->is_virtualized()); } TEST(TonDb, CellStat) { diff --git a/crypto/vm/boc.cpp b/crypto/vm/boc.cpp index 3aef7dd10..f4c303411 100644 --- a/crypto/vm/boc.cpp +++ b/crypto/vm/boc.cpp @@ -163,7 +163,7 @@ int BagOfCells::add_root(td::Ref add_root) { if (add_root.is_null()) { return 0; } - LOG_CHECK(add_root->get_virtualization() == 0) << "TODO: support serialization of virtualized cells"; + LOG_CHECK(!add_root->is_virtualized()) << "TODO: support serialization of virtualized cells"; //const Cell::Hash& hash = add_root->get_hash(); //for (const auto& root_info : roots) { //if (root_info.cell->get_hash() == hash) { @@ -217,7 +217,7 @@ td::Result BagOfCells::import_cell(td::Ref cell, int depth) { cell_list_[pos].should_cache = true; return pos; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return td::Status::Error( "error while importing a cell into a bag of cells: cell has non-zero virtualization level"); } diff --git a/crypto/vm/cells/Cell.cpp b/crypto/vm/cells/Cell.cpp index 1c20ba41a..9bed3481d 100644 --- a/crypto/vm/cells/Cell.cpp +++ b/crypto/vm/cells/Cell.cpp @@ -48,8 +48,8 @@ td::Status Cell::check_equals_unloaded(const Ref& other) const { return td::Status::OK(); } -Ref Cell::virtualize(VirtualizationParameters virt) const { - return VirtualCell::create(virt, Ref(this)); +Ref Cell::virtualize(td::uint32 effective_level) const { + return VirtualCell::create(effective_level, Ref(this)); } std::ostream& operator<<(std::ostream& os, const Cell& c) { diff --git a/crypto/vm/cells/Cell.h b/crypto/vm/cells/Cell.h index e2b47ffc0..8c81bb890 100644 --- a/crypto/vm/cells/Cell.h +++ b/crypto/vm/cells/Cell.h @@ -25,7 +25,6 @@ #include "vm/cells/CellTraits.h" #include "vm/cells/CellUsageTree.h" #include "vm/cells/LevelMask.h" -#include "vm/cells/VirtualizationParameters.h" #include "td/utils/Status.h" @@ -38,10 +37,9 @@ class DataCell; class Cell : public CellTraits { public: using LevelMask = detail::LevelMask; - using VirtualizationParameters = detail::VirtualizationParameters; struct LoadedCell { Ref data_cell; - VirtualizationParameters virt; + td::uint32 effective_level; CellUsageTree::NodePtr tree_node; // TODO: inline_vector? }; @@ -57,8 +55,9 @@ class Cell : public CellTraits { // load interface virtual td::Status set_data_cell(Ref &&data_cell) const = 0; virtual td::Result load_cell() const = 0; - virtual Ref virtualize(VirtualizationParameters virt) const; - virtual td::uint32 get_virtualization() const = 0; + virtual Ref virtualize(td::uint32 effective_level) const; + // Cell is virtualized if its effective level is less than its actual level. + virtual bool is_virtualized() const = 0; virtual CellUsageTree::NodePtr get_tree_node() const = 0; virtual bool is_loaded() const = 0; diff --git a/crypto/vm/cells/CellBuilder.cpp b/crypto/vm/cells/CellBuilder.cpp index a9ad449e1..f99cd86d9 100644 --- a/crypto/vm/cells/CellBuilder.cpp +++ b/crypto/vm/cells/CellBuilder.cpp @@ -100,7 +100,7 @@ Ref CellBuilder::finalize(bool special) { } Ref CellBuilder::create_pruned_branch(Ref cell, td::uint32 new_level, td::uint32 virt_level) { - if (cell->is_loaded() && cell->get_level() <= virt_level && cell->get_virtualization() == 0) { + if (cell->is_loaded() && cell->get_level() <= virt_level && !cell->is_virtualized()) { CellSlice cs(NoVm{}, cell); if (cs.size_refs() == 0) { return cell; diff --git a/crypto/vm/cells/CellSlice.cpp b/crypto/vm/cells/CellSlice.cpp index bea20f95d..8bebb41b3 100644 --- a/crypto/vm/cells/CellSlice.cpp +++ b/crypto/vm/cells/CellSlice.cpp @@ -30,7 +30,7 @@ CellSlice::CellSlice(Ref&& ref) : cell(std::move(ref)), bits_st(0), refs_s */ CellSlice::CellSlice(VirtualCell::LoadedCell loaded_cell) - : virt(loaded_cell.virt) + : effective_level(loaded_cell.effective_level) , cell(std::move(loaded_cell.data_cell)) , tree_node(std::move(loaded_cell.tree_node)) , bits_st(0) @@ -79,7 +79,7 @@ CellSlice::CellSlice(Ref ref) : CellSlice(VirtualCell::LoadedCell{std: CellSlice::CellSlice(const CellSlice& cs) = default; bool CellSlice::load(VirtualCell::LoadedCell loaded_cell) { - virt = loaded_cell.virt; + effective_level = loaded_cell.effective_level; cell = std::move(loaded_cell.data_cell); tree_node = std::move(loaded_cell.tree_node); bits_st = 0; @@ -125,7 +125,7 @@ CellSlice::CellSlice(Ref dc_ref, unsigned _bits_en, unsigned _refs_en, */ CellSlice::CellSlice(const CellSlice& cs, unsigned _bits_en, unsigned _refs_en, unsigned _bits_st, unsigned _refs_st) - : virt(cs.virt) + : effective_level(cs.effective_level) , cell(cs.cell) , tree_node(cs.tree_node) , bits_st(cs.bits_st + _bits_st) @@ -142,7 +142,7 @@ CellSlice::CellSlice(const CellSlice& cs, unsigned _bits_en, unsigned _refs_en, } CellSlice::CellSlice(const CellSlice& cs, unsigned _bits_en, unsigned _refs_en) - : virt(cs.virt) + : effective_level(cs.effective_level) , cell(cs.cell) , tree_node(cs.tree_node) , bits_st(cs.bits_st) @@ -158,7 +158,7 @@ CellSlice::CellSlice(const CellSlice& cs, unsigned _bits_en, unsigned _refs_en) } Cell::LoadedCell CellSlice::move_as_loaded_cell() { - Cell::LoadedCell res{std::move(cell), std::move(virt), std::move(tree_node)}; + Cell::LoadedCell res{std::move(cell), effective_level, std::move(tree_node)}; clear(); return res; } @@ -203,13 +203,13 @@ void CellSlice::error() { */ unsigned CellSlice::get_cell_level() const { - return cell->get_level_mask().apply(virt.get_level()).get_level(); + return cell->get_level_mask().apply(effective_level).get_level(); } unsigned CellSlice::get_level() const { unsigned l = 0; for (unsigned i = refs_st; i < refs_en; i++) { - auto res = cell->get_ref(i)->virtualize(child_virt()); + auto res = cell->get_ref(i)->virtualize(child_effective_level()); unsigned l1 = res->get_level(); // maybe l1 = cell->get_ref(i)->get_level_mask().apply(virt.get_level()).get_level(); if (l1 > l) { @@ -223,7 +223,7 @@ Ref CellSlice::get_base_cell() const { if (cell.is_null()) { return {}; } - auto res = cell->virtualize(virt); + auto res = cell->virtualize(effective_level); if (!tree_node.empty()) { res = UsageCell::create(std::move(res), tree_node); } @@ -740,7 +740,7 @@ bool CellSlice::prefetch_bytes(td::MutableSlice slice) const { Ref CellSlice::prefetch_ref(unsigned offset) const { if (offset < size_refs()) { auto ref_id = refs_st + offset; - auto res = cell->get_ref(ref_id)->virtualize(child_virt()); + auto res = cell->get_ref(ref_id)->virtualize(child_effective_level()); if (!tree_node.empty()) { res = UsageCell::create(std::move(res), tree_node.create_child(ref_id)); } @@ -753,7 +753,7 @@ Ref CellSlice::prefetch_ref(unsigned offset) const { Ref CellSlice::fetch_ref() { if (have_refs()) { auto ref_id = refs_st++; - auto res = cell->get_ref(ref_id)->virtualize(child_virt()); + auto res = cell->get_ref(ref_id)->virtualize(child_effective_level()); if (!tree_node.empty()) { res = UsageCell::create(std::move(res), tree_node.create_child(ref_id)); } @@ -1083,9 +1083,8 @@ VirtualCell::LoadedCell load_cell_slice_impl(Ref cell, bool* can_be_specia } auto loaded_cell = r_loaded_cell.move_as_ok(); if (loaded_cell.data_cell->special_type() == DataCell::SpecialType::PrunnedBranch) { - auto virtualization = loaded_cell.virt.get_virtualization(); - if (virtualization != 0) { - throw VmVirtError{virtualization}; + if (loaded_cell.effective_level < loaded_cell.data_cell->get_level()) { + throw VmVirtError{1}; } } if (can_be_special) { @@ -1111,7 +1110,7 @@ VirtualCell::LoadedCell load_cell_slice_impl(Ref cell, bool* can_be_specia } throw VmError{Excno::cell_und, "failed to load library cell (no vm_state_interface available)"}; } else if (loaded_cell.data_cell->special_type() == DataCell::SpecialType::PrunnedBranch) { - CHECK(loaded_cell.virt.get_virtualization() == 0); + CHECK(loaded_cell.effective_level >= loaded_cell.data_cell->get_level()); throw VmError{Excno::cell_und, "trying to load prunned cell"}; } throw VmError{Excno::cell_und, "unexpected special cell"}; diff --git a/crypto/vm/cells/CellSlice.h b/crypto/vm/cells/CellSlice.h index 7525272b5..7d4a5fb65 100644 --- a/crypto/vm/cells/CellSlice.h +++ b/crypto/vm/cells/CellSlice.h @@ -32,7 +32,7 @@ struct NoVmOrd {}; struct NoVmSpec {}; class CellSlice : public td::CntObject { - Cell::VirtualizationParameters virt; + td::uint32 effective_level; Ref cell; CellUsageTree::NodePtr tree_node; unsigned bits_st, refs_st; @@ -84,9 +84,6 @@ class CellSlice : public td::CntObject { return cell->special_type(); } int child_merkle_depth(int merkle_depth) const { - if (merkle_depth == Cell::VirtualizationParameters::max_level()) { - return merkle_depth; - } if (cell->special_type() == Cell::SpecialType::MerkleProof || cell->special_type() == Cell::SpecialType::MerkleUpdate) { merkle_depth++; @@ -289,9 +286,8 @@ class CellSlice : public td::CntObject { void init_bits_refs(); void init_preload() const; void preload_at_least(unsigned req_bits) const; - Cell::VirtualizationParameters child_virt() const { - return Cell::VirtualizationParameters(static_cast(child_merkle_depth(virt.get_level())), - virt.get_virtualization()); + td::uint32 child_effective_level() const { + return child_merkle_depth(effective_level); } }; diff --git a/crypto/vm/cells/DataCell.cpp b/crypto/vm/cells/DataCell.cpp index b6ff8021f..f4da28b8f 100644 --- a/crypto/vm/cells/DataCell.cpp +++ b/crypto/vm/cells/DataCell.cpp @@ -71,16 +71,13 @@ class CellChecker { return td::Status::Error("Invalid special cell type"); } - // Afterwards, we do some common checks and compute virtualization level. + // Afterwards, we validate depth array and figure out if this cell should be virtualized. if (*std::max_element(depth_.begin(), depth_.end()) > CellTraits::max_depth) { return td::Status::Error("Depth is too big"); } for (int i = 0; i < refs_cnt_; ++i) { - virtualization_ = std::max(virtualization_, refs_[i]->get_virtualization()); - } - if (virtualization_ > std::numeric_limits::max()) { - return td::Status::Error("Virtualization is too big to be stored in vm::DataCell"); + virtualized_ |= refs_[i]->is_virtualized(); } // And finally, we compute cell hashes. @@ -111,8 +108,8 @@ class CellChecker { return level_mask_; } - td::uint8 virtualization() const { - return static_cast(virtualization_); + bool virtualized() const { + return virtualized_; } std::array const& depths() const { @@ -314,7 +311,7 @@ class CellChecker { int bit_length_; Cell::LevelMask level_mask_; - td::uint32 virtualization_{0}; + bool virtualized_{false}; std::array depth_{}; std::array hash_{}; }; @@ -353,7 +350,7 @@ td::Result> DataCell::create(td::Slice data, int bit_length, td::S void* storage = use_arena ? allocate_in_arena(cell_size) : ::operator new(cell_size); DataCell* allocated_cell = new (storage) - DataCell{bit_length, refs.size(), checker.type(), checker.level_mask(), use_arena, checker.virtualization()}; + DataCell{bit_length, refs.size(), checker.type(), checker.level_mask(), use_arena, checker.virtualized()}; auto& cell = *allocated_cell; auto mutable_data = cell.trailer_ + level_info_size; @@ -443,14 +440,14 @@ std::string DataCell::to_hex() const { } DataCell::DataCell(int bit_length, size_t refs_cnt, Cell::SpecialType type, LevelMask level_mask, - bool allocated_in_arena, td::uint8 virtualization) + bool allocated_in_arena, bool virtualized) : bit_length_(bit_length) , refs_cnt_(static_cast(refs_cnt)) , type_(static_cast(type)) , level_(static_cast(level_mask.get_level())) , level_mask_(level_mask.get_mask()) , allocated_in_arena_(allocated_in_arena) - , virtualization_(virtualization) { + , virtualized_(virtualized) { get_thread_safe_counter().add(1); } diff --git a/crypto/vm/cells/DataCell.h b/crypto/vm/cells/DataCell.h index 172b3390a..9e2e52b0e 100644 --- a/crypto/vm/cells/DataCell.h +++ b/crypto/vm/cells/DataCell.h @@ -69,13 +69,13 @@ class DataCell final : public Cell { virtual td::Result load_cell() const override { return LoadedCell{ .data_cell = Ref{this}, - .virt = {}, + .effective_level = level_, .tree_node = {}, }; } - virtual td::uint32 get_virtualization() const override { - return virtualization_; + virtual bool is_virtualized() const override { + return virtualized_; } virtual CellUsageTree::NodePtr get_tree_node() const override { @@ -169,7 +169,7 @@ class DataCell final : public Cell { } DataCell(int bit_length, size_t refs_cnt, Cell::SpecialType type, LevelMask level_mask, bool allocated_in_arena, - td::uint8 virtualization); + bool virtualized); detail::LevelInfo const* level_info() const { return reinterpret_cast(trailer_); @@ -197,7 +197,7 @@ class DataCell final : public Cell { unsigned level_ : 3; unsigned level_mask_ : 3; unsigned allocated_in_arena_ : 1; - unsigned virtualization_ : 8; + unsigned virtualized_ : 1; std::array, max_refs> refs_{}; diff --git a/crypto/vm/cells/ExtCell.h b/crypto/vm/cells/ExtCell.h index dbbd8575b..e2188fd7a 100644 --- a/crypto/vm/cells/ExtCell.h +++ b/crypto/vm/cells/ExtCell.h @@ -54,10 +54,11 @@ class ExtCell : public Cell { td::Result load_cell() const override { TRY_RESULT(data_cell, load_data_cell()); - return LoadedCell{std::move(data_cell), {}, {}}; + auto level = data_cell->get_level(); + return LoadedCell{std::move(data_cell), level, {}}; } - td::uint32 get_virtualization() const override { - return 0; + bool is_virtualized() const override { + return false; } CellUsageTree::NodePtr get_tree_node() const override { return {}; diff --git a/crypto/vm/cells/MerkleProof.cpp b/crypto/vm/cells/MerkleProof.cpp index 26dff7879..4e5b73097 100644 --- a/crypto/vm/cells/MerkleProof.cpp +++ b/crypto/vm/cells/MerkleProof.cpp @@ -106,8 +106,8 @@ Ref MerkleProof::generate_raw(Ref cell, CellUsageTree *usage_tree) { return detail::MerkleProofImpl(usage_tree).create_from(cell); } -Ref MerkleProof::virtualize_raw(Ref cell, Cell::VirtualizationParameters virt) { - return cell->virtualize(virt); +Ref MerkleProof::virtualize_raw(Ref cell, td::uint32 effective_level) { + return cell->virtualize(effective_level); } Ref MerkleProof::generate(Ref cell, IsPrunnedFunction is_prunned) { @@ -144,12 +144,12 @@ td::Result> unpack_proof(Ref cell) { return cs.fetch_ref(); } -Ref MerkleProof::virtualize(Ref cell, int virtualization) { +Ref MerkleProof::virtualize(Ref cell) { auto r_raw = unpack_proof(std::move(cell)); if (r_raw.is_error()) { return {}; } - return virtualize_raw(r_raw.move_as_ok(), {0 /*level*/, static_cast(virtualization)}); + return virtualize_raw(r_raw.move_as_ok(), 0); } class MerkleProofCombineFast { diff --git a/crypto/vm/cells/MerkleProof.h b/crypto/vm/cells/MerkleProof.h index fc2cb6ebd..74c26c2e9 100644 --- a/crypto/vm/cells/MerkleProof.h +++ b/crypto/vm/cells/MerkleProof.h @@ -35,7 +35,7 @@ class MerkleProof { static Ref generate(Ref cell, CellUsageTree *usage_tree); // cell must have zero level and must be a MerkleProof - static Ref virtualize(Ref cell, int virtualization); + static Ref virtualize(Ref cell); static Ref combine(Ref a, Ref b); static td::Result> combine_status(Ref a, Ref b); @@ -46,7 +46,7 @@ class MerkleProof { // works fine with cell of non-zero level, but this is not supported (yet?) in MerkeProof special cell static Ref generate_raw(Ref cell, IsPrunnedFunction is_prunned); static Ref generate_raw(Ref cell, CellUsageTree *usage_tree); - static Ref virtualize_raw(Ref cell, Cell::VirtualizationParameters virt); + static Ref virtualize_raw(Ref cell, td::uint32 effective_level); static Ref combine_raw(Ref a, Ref b); static Ref combine_fast_raw(Ref a, Ref b); }; diff --git a/crypto/vm/cells/PrunnedCell.h b/crypto/vm/cells/PrunnedCell.h index f4d40c285..d25e3bc01 100644 --- a/crypto/vm/cells/PrunnedCell.h +++ b/crypto/vm/cells/PrunnedCell.h @@ -129,8 +129,8 @@ class PrunnedCell final : public Cell { explicit PrunnedCell(Info info, ExtraT&& extra) : info_(info), extra_(std::move(extra)) { } - td::uint32 get_virtualization() const override { - return 0; + virtual bool is_virtualized() const override { + return false; } CellUsageTree::NodePtr get_tree_node() const override { return {}; diff --git a/crypto/vm/cells/UsageCell.h b/crypto/vm/cells/UsageCell.h index 978b91f76..ca0b887cd 100644 --- a/crypto/vm/cells/UsageCell.h +++ b/crypto/vm/cells/UsageCell.h @@ -48,8 +48,8 @@ class UsageCell : public Cell { } return std::move(loaded_cell); } - Ref virtualize(VirtualizationParameters virt) const override { - auto virtualized_cell = cell_->virtualize(virt); + Ref virtualize(td::uint32 effective_level) const override { + auto virtualized_cell = cell_->virtualize(effective_level); if (tree_node_.empty()) { return virtualized_cell; } @@ -59,8 +59,8 @@ class UsageCell : public Cell { return create(std::move(virtualized_cell), tree_node_); } - td::uint32 get_virtualization() const override { - return cell_->get_virtualization(); + bool is_virtualized() const override { + return cell_->is_virtualized(); } CellUsageTree::NodePtr get_tree_node() const override { diff --git a/crypto/vm/cells/VirtualCell.h b/crypto/vm/cells/VirtualCell.h index a75bdf9de..b89df3eb6 100644 --- a/crypto/vm/cells/VirtualCell.h +++ b/crypto/vm/cells/VirtualCell.h @@ -25,15 +25,15 @@ class VirtualCell : public Cell { struct PrivateTag {}; public: - static Ref create(VirtualizationParameters virt, Ref cell) { - if (cell->get_level() <= virt.get_level()) { + static Ref create(td::uint32 effective_level, Ref cell) { + if (cell->get_level() <= effective_level) { return cell; } - return Ref{true, virt, std::move(cell), PrivateTag{}}; + return Ref{true, effective_level, std::move(cell), PrivateTag{}}; } - VirtualCell(VirtualizationParameters virt, Ref cell, PrivateTag) : virt_(virt), cell_(std::move(cell)) { - CHECK(cell_->get_virtualization() <= virt_.get_virtualization()); + VirtualCell(td::uint32 effective_level, Ref cell, PrivateTag) + : effective_level_(effective_level), cell_(std::move(cell)) { } // load interface @@ -42,20 +42,19 @@ class VirtualCell : public Cell { } td::Result load_cell() const override { TRY_RESULT(loaded_cell, cell_->load_cell()); - loaded_cell.virt = loaded_cell.virt.apply(virt_); + loaded_cell.effective_level = std::min(loaded_cell.effective_level, effective_level_); return std::move(loaded_cell); } - Ref virtualize(VirtualizationParameters virt) const override { - auto new_virt = virt_.apply(virt); - if (new_virt == virt_) { + Ref virtualize(td::uint32 new_effective_level) const override { + if (effective_level_ <= new_effective_level) { return Ref(this); } - return create(new_virt, cell_); + return create(new_effective_level, cell_); } - td::uint32 get_virtualization() const override { - return virt_.get_virtualization(); + bool is_virtualized() const override { + return true; } CellUsageTree::NodePtr get_tree_node() const override { @@ -68,23 +67,19 @@ class VirtualCell : public Cell { // hash and level LevelMask get_level_mask() const override { - return cell_->get_level_mask().apply(virt_.get_level()); + return cell_->get_level_mask().apply(effective_level_); } protected: const Hash do_get_hash(td::uint32 level) const override { - return cell_->get_hash(fix_level(level)); + return cell_->get_hash(std::min(effective_level_, level)); } td::uint16 do_get_depth(td::uint32 level) const override { - return cell_->get_depth(fix_level(level)); + return cell_->get_depth(std::min(effective_level_, level)); } private: - VirtualizationParameters virt_; + td::uint32 effective_level_; Ref cell_; - - int fix_level(int level) const { - return get_level_mask().apply(level).get_level(); - } }; } // namespace vm diff --git a/crypto/vm/cells/VirtualizationParameters.h b/crypto/vm/cells/VirtualizationParameters.h deleted file mode 100644 index b83e87d23..000000000 --- a/crypto/vm/cells/VirtualizationParameters.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - This file is part of TON Blockchain Library. - - TON Blockchain Library is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as published by - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. - - TON Blockchain Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with TON Blockchain Library. If not, see . - - Copyright 2017-2020 Telegram Systems LLP -*/ -#pragma once - -#include "td/utils/int_types.h" -#include "td/utils/logging.h" - -#include - -namespace vm { -namespace detail { -class VirtualizationParameters { - public: - static constexpr td::uint8 max_level() { - return std::numeric_limits::max(); - } - - VirtualizationParameters() = default; - - VirtualizationParameters(td::uint8 level, td::uint8 virtualization) : level_(level), virtualization_(virtualization) { - CHECK(virtualization_ != 0 || empty()); - } - - bool empty() const { - return level_ == max_level() && virtualization_ == 0; - } - - VirtualizationParameters apply(VirtualizationParameters outer) const { - if (outer.level_ >= level_) { - return *this; - } - CHECK(virtualization_ <= outer.virtualization_); - return {outer.level_, outer.virtualization_}; - } - - td::uint8 get_level() const { - return level_; - } - - td::uint8 get_virtualization() const { - return virtualization_; - } - - bool operator==(const VirtualizationParameters &other) const { - return level_ == other.level_ && virtualization_ == other.virtualization_; - } - - private: - td::uint8 level_ = max_level(); - td::uint8 virtualization_ = 0; -}; -inline td::StringBuilder &operator<<(td::StringBuilder &sb, const VirtualizationParameters &virt) { - return sb << "{level: " << virt.get_level() << ", virtualization: " << virt.get_virtualization() << "}"; -} -} // namespace detail -} // namespace vm diff --git a/crypto/vm/db/DynamicBagOfCellsDb.cpp b/crypto/vm/db/DynamicBagOfCellsDb.cpp index 697e4d67f..1b91bd297 100644 --- a/crypto/vm/db/DynamicBagOfCellsDb.cpp +++ b/crypto/vm/db/DynamicBagOfCellsDb.cpp @@ -217,7 +217,7 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_inc_.push_back(cell); @@ -226,7 +226,7 @@ class DynamicBagOfCellsDbImpl : public DynamicBagOfCellsDb, private ExtCellCreat if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_dec_.push_back(cell); diff --git a/crypto/vm/db/DynamicBagOfCellsDbV2.cpp b/crypto/vm/db/DynamicBagOfCellsDbV2.cpp index 3b7d7c233..ae06beb1b 100644 --- a/crypto/vm/db/DynamicBagOfCellsDbV2.cpp +++ b/crypto/vm/db/DynamicBagOfCellsDbV2.cpp @@ -844,7 +844,7 @@ class DynamicBagOfCellsDbImplV2 : public DynamicBagOfCellsDb { if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_inc_.push_back(cell); @@ -853,7 +853,7 @@ class DynamicBagOfCellsDbImplV2 : public DynamicBagOfCellsDb { if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_dec_.push_back(cell); diff --git a/crypto/vm/db/InMemoryBagOfCellsDb.cpp b/crypto/vm/db/InMemoryBagOfCellsDb.cpp index 829ed38d8..a41edb6f4 100644 --- a/crypto/vm/db/InMemoryBagOfCellsDb.cpp +++ b/crypto/vm/db/InMemoryBagOfCellsDb.cpp @@ -860,7 +860,7 @@ class InMemoryBagOfCellsDb : public DynamicBagOfCellsDb { if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_inc_.push_back(cell); @@ -870,7 +870,7 @@ class InMemoryBagOfCellsDb : public DynamicBagOfCellsDb { if (cell.is_null()) { return; } - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return; } to_dec_.push_back(cell); diff --git a/crypto/vm/db/StaticBagOfCellsDb.cpp b/crypto/vm/db/StaticBagOfCellsDb.cpp index 215dcfa3b..0279ac77f 100644 --- a/crypto/vm/db/StaticBagOfCellsDb.cpp +++ b/crypto/vm/db/StaticBagOfCellsDb.cpp @@ -45,11 +45,11 @@ class RootCell : public Cell { td::Result load_cell() const override { return cell_->load_cell(); } - Ref virtualize(VirtualizationParameters virt) const override { - return cell_->virtualize(virt); + Ref virtualize(td::uint32 effective_level) const override { + return cell_->virtualize(effective_level); } - td::uint32 get_virtualization() const override { - return cell_->get_virtualization(); + bool is_virtualized() const override { + return cell_->is_virtualized(); } CellUsageTree::NodePtr get_tree_node() const override { return cell_->get_tree_node(); diff --git a/crypto/vm/large-boc-serializer.cpp b/crypto/vm/large-boc-serializer.cpp index 839e6235a..56226f5d8 100644 --- a/crypto/vm/large-boc-serializer.cpp +++ b/crypto/vm/large-boc-serializer.cpp @@ -152,7 +152,7 @@ td::Result LargeBocSerializer::import_cell(Hash root_hash, int root_depth) for (size_t i = 0; i < loaded_results.size(); ++i) { auto& cell = loaded_results[i]; - if (cell->get_virtualization() != 0) { + if (cell->is_virtualized()) { return td::Status::Error( "error while importing a cell into a bag of cells: cell has non-zero virtualization level"); } diff --git a/lite-client/lite-client.cpp b/lite-client/lite-client.cpp index 1050e6d27..68b658534 100644 --- a/lite-client/lite-client.cpp +++ b/lite-client/lite-client.cpp @@ -2345,7 +2345,7 @@ void TestNode::got_one_transaction(ton::BlockIdExt req_blkid, ton::BlockIdExt bl } auto proof_root = P.move_as_ok(); try { - auto block_root = vm::MerkleProof::virtualize(std::move(proof_root), 1); + auto block_root = vm::MerkleProof::virtualize(std::move(proof_root)); if (block_root.is_null()) { LOG(ERROR) << "transaction block proof is invalid"; return; @@ -2795,7 +2795,7 @@ void TestNode::got_config_params(ton::BlockIdExt req_blkid, int mode, std::strin block::check_extract_state_proof(blkid, f->state_proof_.as_slice(), f->config_proof_.as_slice()), PSLICE() << "masterchain state proof for " << blkid.to_str() << " is invalid :"); } else { - block = vm::MerkleProof::virtualize(config_proof, 1); + block = vm::MerkleProof::virtualize(config_proof); if (block.is_null()) { promise.set_error( td::Status::Error("cannot virtualize configuration proof constructed from key block "s + blkid.to_str())); @@ -3181,7 +3181,7 @@ void TestNode::got_block_header_raw(td::BufferSlice res, td::Promiseget_hash().bits(); - TRY_STATUS(block::check_block_header_proof(vm::MerkleProof::virtualize(state_proof, 1), blk_id, &state_hash, true, + TRY_STATUS(block::check_block_header_proof(vm::MerkleProof::virtualize(state_proof), blk_id, &state_hash, true, save_utime, save_lt)); return td::Status::OK(); } @@ -4205,7 +4205,7 @@ static bool visit(Ref cs_ref) { td::Result> TestNode::ValidatorLoadInfo::build_proof(int idx, td::Bits256* save_pubkey) const { try { - auto state_virt_root = vm::MerkleProof::virtualize(std::move(data_proof), 1); + auto state_virt_root = vm::MerkleProof::virtualize(std::move(data_proof)); if (state_virt_root.is_null()) { return td::Status::Error("account state proof is invalid"); } @@ -4536,7 +4536,7 @@ td::Status TestNode::ValidatorLoadInfo::init_check_proofs() { if (lt != end_lt) { return td::Status::Error(PSLICE() << "incorrect block logical time: declared " << end_lt << ", actual " << lt); } - auto vstate = vm::MerkleProof::virtualize(data_proof, 1); + auto vstate = vm::MerkleProof::virtualize(data_proof); if (vstate.is_null()) { return td::Status::Error(PSLICE() << "cannot virtualize state of block " << blk_id.to_str()); } diff --git a/storage/MerkleTree.cpp b/storage/MerkleTree.cpp index 2ba4aeb86..d8767ffce 100644 --- a/storage/MerkleTree.cpp +++ b/storage/MerkleTree.cpp @@ -174,7 +174,7 @@ td::Result> MerkleTree::gen_proof(size_t l, size_t r) const { return td::Status::Error("Got no proofs yet"); } auto usage_tree = std::make_shared(); - auto root_raw = vm::MerkleProof::virtualize(root_proof_, 1); + auto root_raw = vm::MerkleProof::virtualize(root_proof_); auto usage_cell = vm::UsageCell::create(root_raw, usage_tree->root_ptr()); TRY_STATUS(TRY_VM(do_gen_proof(std::move(usage_cell), 0, n_ - 1, l, r))); auto res = vm::MerkleProof::generate(root_raw, usage_tree.get()); @@ -202,7 +202,7 @@ td::Ref MerkleTree::get_root(size_t depth_limit) const { return root_proof_; } auto usage_tree = std::make_shared(); - auto root_raw = vm::MerkleProof::virtualize(root_proof_, 1); + auto root_raw = vm::MerkleProof::virtualize(root_proof_); auto usage_cell = vm::UsageCell::create(root_raw, usage_tree->root_ptr()); do_gen_proof(std::move(usage_cell), unpack_proof(root_proof_).move_as_ok(), depth_limit); auto res = vm::MerkleProof::generate(root_raw, usage_tree.get()); diff --git a/storage/MicrochunkTree.cpp b/storage/MicrochunkTree.cpp index 3249d25b4..d6cb9f6c7 100644 --- a/storage/MicrochunkTree.cpp +++ b/storage/MicrochunkTree.cpp @@ -91,7 +91,7 @@ void MicrochunkTree::Builder::add_microchunk(td::Slice s) { } MicrochunkTree::MicrochunkTree(td::Ref root_proof) : root_proof_(root_proof) { - td::Ref virt_root = vm::MerkleProof::virtualize(root_proof_, 1); + td::Ref virt_root = vm::MerkleProof::virtualize(root_proof_); CHECK(!virt_root.is_null()); CHECK(virt_root->get_depth() <= 50); total_size_ = MICROCHUNK_SIZE << virt_root->get_depth(); diff --git a/storage/TorrentMeta.cpp b/storage/TorrentMeta.cpp index 1a8fdd897..3e5242b55 100644 --- a/storage/TorrentMeta.cpp +++ b/storage/TorrentMeta.cpp @@ -42,7 +42,7 @@ td::Result TorrentMeta::deserialize(td::Slice data) { } } if (res.root_proof.not_null()) { - auto root = vm::MerkleProof::virtualize(res.root_proof, 1); + auto root = vm::MerkleProof::virtualize(res.root_proof); if (root.is_null()) { return td::Status::Error("Root proof is not a merkle proof"); } diff --git a/tonlib/tonlib/TonlibClient.cpp b/tonlib/tonlib/TonlibClient.cpp index 4ddcbbfab..3cd6b5f45 100644 --- a/tonlib/tonlib/TonlibClient.cpp +++ b/tonlib/tonlib/TonlibClient.cpp @@ -1685,7 +1685,7 @@ class GetShardBlockProof : public td::actor::Actor { abort(TonlibError::InvalidBagOfCells("proof")); return; } - auto block_root = vm::MerkleProof::virtualize(R.move_as_ok(), 1); + auto block_root = vm::MerkleProof::virtualize(R.move_as_ok()); if (cur_id.root_hash != block_root->get_hash().bits()) { abort(td::Status::Error("invalid block hash in proof")); return; @@ -1851,7 +1851,7 @@ class RunEmulator : public TonlibQueryActor { TRY_RESULT(root, vm::std_boc_deserialize(std::move(header->header_proof_))); try { - auto virt_root = vm::MerkleProof::virtualize(root, 1); + auto virt_root = vm::MerkleProof::virtualize(root); if (virt_root.is_null()) { return td::Status::Error("block header proof is not a valid Merkle proof"); } @@ -5644,7 +5644,7 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_getShards& request, return data_cell.move_as_error_prefix("Couldn't deserialize shards data: "); } try { - auto virt_root = vm::MerkleProof::virtualize(proof_cell.move_as_ok(), 1); + auto virt_root = vm::MerkleProof::virtualize(proof_cell.move_as_ok()); if (virt_root.is_null()) { return td::Status::Error("Virt root is null"); } @@ -5746,7 +5746,7 @@ td::Status check_lookup_block_proof(lite_api_ptrget_hash().bits()) { return td::Status::Error("invalid block hash in proof"); } @@ -5790,7 +5790,7 @@ td::Status check_lookup_block_proof(lite_api_ptrproof_))); - auto virt_root = vm::MerkleProof::virtualize(proof_cell, 1); + auto virt_root = vm::MerkleProof::virtualize(proof_cell); if (root_hash != virt_root->get_hash().bits()) { return td::Status::Error("Invalid block proof root hash"); @@ -6093,7 +6093,7 @@ td::Status TonlibClient::do_request(const tonlib_api::blocks_getBlockHeader& req } else { auto root = R.move_as_ok(); try { - auto virt_root = vm::MerkleProof::virtualize(root, 1); + auto virt_root = vm::MerkleProof::virtualize(root); if (virt_root.is_null()) { return td::Status::Error("Virt root is null"); } else { diff --git a/validator/impl/accept-block.cpp b/validator/impl/accept-block.cpp index de48626d7..814849ec4 100644 --- a/validator/impl/accept-block.cpp +++ b/validator/impl/accept-block.cpp @@ -746,7 +746,7 @@ bool AcceptBlockQuery::unpack_proof_link(BlockIdExt id, Ref proof_lin return fatal_error("block proof link is for another block: expected "s + id.to_str() + ", found " + proof_blk_id.to_str()); } - auto virt_root = vm::MerkleProof::virtualize(proof.root, 1); + auto virt_root = vm::MerkleProof::virtualize(proof.root); if (virt_root.is_null()) { return fatal_error("block proof link for block "s + id.to_str() + " does not contain a valid Merkle proof for the block header"); diff --git a/validator/impl/check-proof.cpp b/validator/impl/check-proof.cpp index 30a13c089..9a563766c 100644 --- a/validator/impl/check-proof.cpp +++ b/validator/impl/check-proof.cpp @@ -149,7 +149,7 @@ bool CheckProof::init_parse(bool is_aux) { sig_weight_ = 0; sig_root_.clear(); } - auto virt_root = vm::MerkleProof::virtualize(proof.root, 1); + auto virt_root = vm::MerkleProof::virtualize(proof.root); if (virt_root.is_null()) { return fatal_error("block proof for block "s + proof_blk_id.to_str() + " does not contain a valid Merkle proof for the block header"); diff --git a/validator/impl/ihr-message.cpp b/validator/impl/ihr-message.cpp index 4327b5dd3..a040bb1a6 100644 --- a/validator/impl/ihr-message.cpp +++ b/validator/impl/ihr-message.cpp @@ -76,7 +76,7 @@ td::Result> IhrMessageQ::create_ihr_message(td::BufferSlice dat return td::Status::Error("IHR message does not contain a valid source BlockIdExt"); } try { - auto virt_root = vm::MerkleProof::virtualize(proof, 1); + auto virt_root = vm::MerkleProof::virtualize(proof); if (virt_root.is_null()) { return td::Status::Error("IHR message does not contain a valid Merkle proof"); } diff --git a/validator/impl/out-msg-queue-proof.cpp b/validator/impl/out-msg-queue-proof.cpp index 95ad4a41e..f86dbf3c6 100644 --- a/validator/impl/out-msg-queue-proof.cpp +++ b/validator/impl/out-msg-queue-proof.cpp @@ -192,7 +192,7 @@ td::Result>> OutMsgQueueProof::fetch(Shard block_state_proof = block_state_proofs[j++]; TRY_RESULT_ASSIGN(state_root_hash, unpack_block_state_proof(blocks[i], block_state_proof)); } - auto state_root = vm::MerkleProof::virtualize(queue_proofs[i], 1); + auto state_root = vm::MerkleProof::virtualize(queue_proofs[i]); if (state_root->get_hash().as_slice() != state_root_hash.as_slice()) { return td::Status::Error("state root hash mismatch"); } diff --git a/validator/impl/proof.cpp b/validator/impl/proof.cpp index d72222116..341029e57 100644 --- a/validator/impl/proof.cpp +++ b/validator/impl/proof.cpp @@ -132,7 +132,7 @@ td::Result ProofLinkQ::get_virtual_root(bool lazy) if (proof_blk_id != id_) { return td::Status::Error(-668, "masterchain block proof is for another block"); } - auto virt_root = vm::MerkleProof::virtualize(proof.root, 1); + auto virt_root = vm::MerkleProof::virtualize(proof.root); if (virt_root.is_null()) { return td::Status::Error(-668, "block proof for block "s + proof_blk_id.to_str() + " does not contain a valid Merkle proof for the block header"); @@ -179,7 +179,7 @@ td::Result> create_block_state_proof(td::Ref root) { } td::Result unpack_block_state_proof(BlockIdExt block_id, td::Ref proof) { - auto virt_root = vm::MerkleProof::virtualize(proof, 1); + auto virt_root = vm::MerkleProof::virtualize(proof); if (virt_root.is_null()) { return td::Status::Error("invalid Merkle proof"); } diff --git a/validator/impl/top-shard-descr.cpp b/validator/impl/top-shard-descr.cpp index 9eadeef35..f38d0cbdc 100644 --- a/validator/impl/top-shard-descr.cpp +++ b/validator/impl/top-shard-descr.cpp @@ -39,7 +39,7 @@ ShardTopBlockDescrQ* ShardTopBlockDescrQ::make_copy() const { } td::Status ShardTopBlockDescrQ::unpack_one_proof(BlockIdExt& cur_id, Ref proof_root, bool is_head) { - auto virt_root = vm::MerkleProof::virtualize(proof_root, 1); + auto virt_root = vm::MerkleProof::virtualize(proof_root); if (virt_root.is_null()) { return td::Status::Error(-666, "link for block "s + cur_id.to_str() + " inside ShardTopBlockDescr of " + block_id_.to_str() + @@ -508,7 +508,7 @@ Ref ShardTopBlockDescrQ::get_prev_descr(int pos, int sum_cnt (unsigned)(pos + sum_cnt) > size()) { return {}; } - auto virt_root = vm::MerkleProof::virtualize(proof_roots_.at(pos), 1); + auto virt_root = vm::MerkleProof::virtualize(proof_roots_.at(pos)); auto res = block::McShardHash::from_block(std::move(virt_root), chain_blk_ids_.at(pos).file_hash); if (res.not_null()) { auto& total_fees = res.write().fees_collected_; diff --git a/validator/impl/validate-query.cpp b/validator/impl/validate-query.cpp index 88ae031e2..194011131 100644 --- a/validator/impl/validate-query.cpp +++ b/validator/impl/validate-query.cpp @@ -596,7 +596,7 @@ bool ValidateQuery::extract_collated_data_from(Ref croot, int idx) { if (cs.special_type() != vm::Cell::SpecialType::MerkleProof) { return reject_query("it is a special cell, but not a Merkle proof root"); } - auto virt_root = vm::MerkleProof::virtualize(croot, 1); + auto virt_root = vm::MerkleProof::virtualize(croot); if (virt_root.is_null()) { return reject_query("invalid Merkle proof"); }