Skip to content
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

Svnn ibc proof generation #37

Merged
merged 36 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5900424
added unit test for svnn_ibc proof generation + verification
systemzax Apr 16, 2024
7186456
Changed svnn_ibc contract bitset to use uint32_t block size to align …
systemzax Apr 16, 2024
cbd7b6b
Merge branch 'savanna' into svnn_ibc_proof_generation
systemzax Apr 16, 2024
9c1c888
changed bitset instanciation in svnn_ibc_tests, fixed cast in svnn_ib…
systemzax Apr 17, 2024
0c6417d
Merge branch 'svnn_ibc_proof_generation' of https://github.com/antelo…
systemzax Apr 17, 2024
32e694a
Explicit type definition for raw_bitset
systemzax Apr 17, 2024
4b8aced
Merge branch 'savanna' into svnn_ibc_proof_generation
systemzax Apr 17, 2024
0b65953
Use finality_test_cluster in ibc test
systemzax Apr 21, 2024
fa7588d
Improvements to ibc contract bitset
systemzax Apr 21, 2024
c6b5222
Manual merge
systemzax Apr 21, 2024
f961fbd
Removed leftover comment
systemzax Apr 21, 2024
2c0e42a
Fixed wrong block_num in svnn_ibc contract lastproofs inclusion
systemzax Apr 24, 2024
77d31c6
Compute proof path instead of providing it when calling the contract
systemzax Apr 28, 2024
a63949a
Added tests for light proof + different finality block than target block
systemzax Apr 28, 2024
c9b5094
Refactored to avoid the use of target_data variant
systemzax Apr 28, 2024
23cdef9
Replaced binary interface with string interface for bls_pub_key and b…
systemzax Apr 29, 2024
d66a178
implemented svnn_ibc garbage collection, improved tests coverage
systemzax Apr 29, 2024
b2ceafa
Improved svnn_ibc test comments
systemzax Apr 29, 2024
2350442
svnn_ibc test code cleanup
systemzax Apr 29, 2024
ff4f9a8
Merge remote-tracking branch 'origin/savanna' into svnn_ibc_proof_gen…
systemzax Apr 29, 2024
022c3a7
Adjusted svnn_ibc test to reflect changes in quorum_certificate struct
systemzax Apr 29, 2024
1ca06ab
Manual merge in block_header_state.hpp
systemzax Apr 29, 2024
a335485
Merge branch 'main' into svnn_ibc_proof_generation
systemzax Apr 29, 2024
dcd88fc
Updated bls submodule
systemzax Apr 29, 2024
f47bef6
Updated modules recursively
systemzax Apr 29, 2024
2742928
Revert "Updated modules recursively"
systemzax Apr 29, 2024
e599e1d
Revert "Updated bls submodule"
systemzax Apr 29, 2024
8735b22
Revert "Revert "Updated bls submodule""
systemzax Apr 29, 2024
6dfe3e7
Merge branch 'main' into svnn_ibc_proof_generation
systemzax Apr 29, 2024
28c5490
Update unittests/test-contracts/svnn_ibc/svnn_ibc.hpp
systemzax Apr 30, 2024
e3d1fe3
Merge branch 'main' into svnn_ibc_proof_generation
heifner May 1, 2024
8435fd6
Removed commented out code
systemzax May 2, 2024
c83664f
Misc minor fixes
systemzax May 2, 2024
60ad311
Merge branch 'svnn_ibc_proof_generation' of https://github.com/antelo…
systemzax May 2, 2024
e391806
Removed extra comment
systemzax May 2, 2024
dd1689b
updated bls submodule reference
systemzax May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions libraries/chain/block_header_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ namespace eosio::chain {
// gets updated if a protocol feature causes a breaking change to light block
// header validation

// data for finality_digest
struct finality_digest_data_v1 {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation {0};
digest_type finality_tree_digest;
digest_type active_finalizer_policy_and_base_digest;
};

// compute base_digest explicitly because of pointers involved.
digest_type block_header_state::compute_base_digest() const {
digest_type::encoder enc;
Expand Down Expand Up @@ -221,4 +212,3 @@ block_header_state block_header_state::next(const signed_block_header& h, valida

} // namespace eosio::chain

FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(finality_tree_digest)(active_finalizer_policy_and_base_digest) )
11 changes: 11 additions & 0 deletions libraries/chain/include/eosio/chain/block_header_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ namespace detail { struct schedule_info; };
constexpr uint32_t light_header_protocol_version_major = 1;
constexpr uint32_t light_header_protocol_version_minor = 0;

// data for finality_digest
struct finality_digest_data_v1 {
uint32_t major_version{light_header_protocol_version_major};
uint32_t minor_version{light_header_protocol_version_minor};
uint32_t active_finalizer_policy_generation {0};
digest_type finality_tree_digest;
digest_type active_finalizer_policy_and_base_digest;
};

struct building_block_input {
block_id_type parent_id;
block_timestamp_type parent_timestamp;
Expand Down Expand Up @@ -96,3 +105,5 @@ using block_header_state_ptr = std::shared_ptr<block_header_state>;
FC_REFLECT( eosio::chain::block_header_state, (block_id)(header)
(activated_protocol_features)(core)(active_finalizer_policy)
(active_proposer_policy)(proposer_policies)(finalizer_policies)(header_exts))

FC_REFLECT( eosio::chain::finality_digest_data_v1, (major_version)(minor_version)(active_finalizer_policy_generation)(finality_tree_digest)(active_finalizer_policy_and_base_digest) )
140 changes: 140 additions & 0 deletions unittests/svnn_ibc_test_cluster.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#pragma once
linh2931 marked this conversation as resolved.
Show resolved Hide resolved

#include <eosio/chain/block.hpp>
#include <eosio/chain/hotstuff/finalizer_authority.hpp>
#include <fc/crypto/bls_private_key.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <boost/test/unit_test.hpp>
#pragma GCC diagnostic pop
#include <eosio/testing/tester.hpp>

// Set up a test network which consists of 3 nodes:
// * node0 produces blocks and pushes them to node1 and node2;
// node0 votes the blocks it produces internally.
// * node1 votes on the proposal sent by node0
// * node2 votes on the proposal sent by node0
// Each node has one finalizer: node0 -- "node0"_n, node1 -- "node1"_n, node2 -- "node2"_n.
// Quorum is set to 2.
// At start up, head is at the IF Genesis block

using namespace eosio::chain;

class svnn_ibc_test_cluster {
public:

enum class vote_mode {
strong,
weak,
};

struct node_info {
eosio::testing::tester node;
uint32_t prev_lib_num{0};
std::vector<eosio::chain::vote_message> votes;
fc::crypto::blslib::bls_private_key priv_key;
};

// Construct a test network and set head to IF Genesis for all nodes
svnn_ibc_test_cluster() {
using namespace eosio::testing;

setup_node(node0, "node0"_n);
setup_node(node1, "node1"_n);
setup_node(node2, "node2"_n);

// collect node1's votes
node1.node.control->voted_block().connect( [&]( const eosio::chain::vote_message& vote ) {
node1.votes.emplace_back(vote);
});
// collect node2's votes
node2.node.control->voted_block().connect( [&]( const eosio::chain::vote_message& vote ) {
node2.votes.emplace_back(vote);
});

}

// send node1's vote identified by "vote_index" in the collected votes
eosio::chain::vote_status process_node1_vote(uint32_t vote_index, vote_mode mode = vote_mode::strong) {
return process_vote( node1, vote_index, mode );
}

// send node1's latest vote
eosio::chain::vote_status process_node1_vote(vote_mode mode = vote_mode::strong) {
return process_vote( node1, mode );
}

// send node2's vote identified by "vote_index" in the collected votes
eosio::chain::vote_status process_node2_vote(uint32_t vote_index, vote_mode mode = vote_mode::strong) {
return process_vote( node2, vote_index, mode );
}

// send node2's latest vote
eosio::chain::vote_status process_node2_vote(vote_mode mode = vote_mode::strong) {
return process_vote( node2, mode );
}

// node0 produces a block and pushes it to node1 and node2
signed_block_ptr produce_and_push_block() {
signed_block_ptr b = node0.node.produce_block();
node1.node.push_block(b);
node2.node.push_block(b);
return b;
}

std::array<node_info, 3> nodes;
node_info& node0 = nodes[0];
node_info& node1 = nodes[1];
node_info& node2 = nodes[2];

eosio::chain::vote_message node1_orig_vote;

// sets up "node_index" node
void setup_node(node_info& node, eosio::chain::account_name local_finalizer) {
using namespace eosio::testing;

//pre-IF

auto block_1 = node.node.produce_block();
auto block_2 = node.node.produce_block();

// activate IF
eosio::testing::base_tester::finalizer_policy_input policy_input = {
.finalizers = { {.name = "node0"_n, .weight = 1},
{.name = "node1"_n, .weight = 1},
{.name = "node2"_n, .weight = 1}},
.threshold = 2,
.local_finalizers = {local_finalizer}
};

auto [trace_ptr, priv_keys] = node.node.set_finalizers(policy_input);
FC_ASSERT( priv_keys.size() == 1, "number of private keys should be 1" );
node.priv_key = priv_keys[0]; // we only have one private key

}

// send a vote to node0
eosio::chain::vote_status process_vote(node_info& node, size_t vote_index, vote_mode mode) {
FC_ASSERT( vote_index < node.votes.size(), "out of bound index in process_vote" );
auto& vote = node.votes[vote_index];
if( mode == vote_mode::strong ) {
vote.strong = true;
} else {
vote.strong = false;

// fetch the strong digest
auto strong_digest = node.node.control->get_strong_digest_by_id(vote.block_id);
// convert the strong digest to weak and sign it
vote.sig = node.priv_key.sign(eosio::chain::create_weak_digest(strong_digest));
}

return node0.node.control->process_vote_message( vote );
}

eosio::chain::vote_status process_vote(node_info& node, vote_mode mode) {
auto vote_index = node.votes.size() - 1;
return process_vote( node, vote_index, mode );
}

};
Loading
Loading