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

[1.0.3] Finality violation tests 1.0.0 #610

Open
wants to merge 72 commits into
base: release/1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
686986e
Added placeholder svnn_finality_violation.cpp and updated cmake files
systemzax Jul 29, 2024
b345e76
Added placeholder finality_violation smart contract
systemzax Jul 29, 2024
920d7aa
Converted proof_test_cluster to use fixed size nodes, added vote_prop…
systemzax Jul 29, 2024
0f83dea
Added vote propagation tests
systemzax Jul 29, 2024
2eff199
Initial set up for finality violation tests
systemzax Jul 29, 2024
38ccb3b
Progress on initial tests
systemzax Jul 31, 2024
cbcbc27
Comments related to rule #1 violation
systemzax Jul 31, 2024
a686f00
Updated ibc_block_data_t structure to expose all level 2 and level 3 …
systemzax Jul 31, 2024
a82435a
Updated savanna contract common code to support level 3 commitments
systemzax Jul 31, 2024
e295f9d
Added rule #1 finality violation action to smart contract, tests
systemzax Jul 31, 2024
bca8c83
Remove commented out code
systemzax Jul 31, 2024
84f6c08
Removed unused parameter in svnn_ibc_tests
systemzax Jul 31, 2024
3fc7806
Changed pending_finalizer_policy to last_pending_finalizer_policy in …
systemzax Aug 1, 2024
5a26775
Updated finality violation tests to reflect new name
systemzax Aug 1, 2024
90f5f45
Renamed last_pending_finalizer_policy_generation to pending_finalizer…
systemzax Aug 1, 2024
e7d3263
Removed temporary checkpoints from svnn_ibc_tests
systemzax Aug 1, 2024
9e90bbf
Small refactor of finality violation tests
systemzax Aug 1, 2024
484c229
Prepared test for rule #2
systemzax Aug 1, 2024
4da02e7
Implemented rule #2 verification in savanna contracts, improved proof
systemzax Aug 1, 2024
5acaae2
Added savanna contract interface for weak QCs
systemzax Aug 1, 2024
7ea485e
Completed savanna contract support for weak QCs
systemzax Aug 1, 2024
1be2257
Reordered proof generation to ensure only the most recent information…
systemzax Aug 1, 2024
891207d
WIP
systemzax Aug 1, 2024
19d1b5d
Replaced policy digests and generations returned by process_result fu…
systemzax Aug 1, 2024
2f5a557
Modified tests to use light client data cache only
systemzax Aug 1, 2024
67440e4
Removed leftover comments
systemzax Aug 1, 2024
3559929
Minor code reorganization plus added comments for clarity
systemzax Aug 1, 2024
ec68dd5
Fixed incorrect assignement in savanna contract, recompiled contract
systemzax Aug 1, 2024
0ff0c8d
Corrected order and names of sub rules
systemzax Aug 1, 2024
a99e673
Desambiguated rule2 (now rule2a and rule2b) to differentiate between …
systemzax Aug 1, 2024
772eeb2
misc
systemzax Aug 6, 2024
792462d
Refactored light client data cache to properly evaluate finality rule…
systemzax Aug 6, 2024
00820b2
Rule 2 WIP
systemzax Aug 7, 2024
ead0837
Completed rule 2
systemzax Aug 7, 2024
f408f9f
Clean up
systemzax Aug 7, 2024
81bf80b
Renamed minimal_block_data to finality_block_data
systemzax Aug 8, 2024
18deabb
Adjusted order of events to more closely reflect the light client beh…
systemzax Aug 8, 2024
9c47427
Obtain reference to fake chain blocks via the list of reversible bloc…
systemzax Aug 8, 2024
26e809b
Added rule #3 to smart contract
systemzax Aug 8, 2024
b1761b2
Added proof of rule #3 finality violation test
systemzax Aug 8, 2024
e1c8e41
Added comments to smart contract, recompiled
systemzax Aug 8, 2024
19e5591
Fixed a few bugs, added additional rule #3 test where fake chain is a…
systemzax Aug 8, 2024
411adc2
Updated finality violation contract actions to return guilty vs innoc…
systemzax Aug 8, 2024
a62ab3f
Added bitset tests to ibc tests to cover the exact blame and exonerat…
systemzax Aug 8, 2024
fa81154
Removed unused return statements, added comments about bitset verific…
systemzax Aug 8, 2024
264a2b9
Resolved merge conflict
systemzax Aug 26, 2024
b10e275
Converted some static functions to inline functions in finality_proof
systemzax Aug 26, 2024
17355c8
Re-enabled action traces size check in finality_proof
systemzax Aug 26, 2024
14f8873
Pass result to process_result by const reference
systemzax Aug 26, 2024
b223247
Removed unnecessary check to process_finalizer_votes, removed comment…
systemzax Aug 26, 2024
e92e125
Updated functions svnn_finality_violation_tests to use const referenc…
systemzax Aug 26, 2024
52436cf
Simplified shouldPass function, removed unnecessary try catch
systemzax Aug 26, 2024
891296e
Updated savanna contracts to pass function parameters by const refere…
systemzax Aug 26, 2024
f07308f
Replaced find_if with lower_bound to perform binary search in svnn_fi…
systemzax Aug 26, 2024
1e1f0e4
bumped chainbase submodule
systemzax Aug 26, 2024
d1a4ee9
Merge branch 'release/1.0' into finality_violation_tests_1.0.0
systemzax Aug 26, 2024
d48f25c
Merge branch 'release/1.0' into finality_violation_tests_1.0.0
systemzax Aug 27, 2024
5e0953e
Merge branch 'release/1.0' into finality_violation_tests_1.0.0
systemzax Aug 27, 2024
9bdddce
Merge branch 'release/1.0' into finality_violation_tests_1.0.0
systemzax Aug 28, 2024
513c350
Merge branch 'release/1.0' of https://github.com/AntelopeIO/spring in…
systemzax Sep 1, 2024
d715a31
Replaced static functions with inline functions in finality_proof
systemzax Sep 1, 2024
e85e5f8
Removed default empty initializers in ibc_block_data_t
systemzax Sep 1, 2024
243c11d
Simplified the pruning function in data cache struct
systemzax Sep 1, 2024
8d8d4ba
Removed commented out code
systemzax Sep 1, 2024
4946954
Merge branch 'finality_violation_tests_1.0.0' of https://github.com/A…
systemzax Sep 1, 2024
68c2c1d
Moved finality digests comparison to the check_qcs function in finali…
systemzax Sep 3, 2024
bae1c27
Fixed lock violation check
systemzax Sep 3, 2024
6c253f5
Added bool flag to check_qc to control whether or not we verify the q…
systemzax Sep 3, 2024
1b7fb4f
Renamed finalizers to strong_votes in savanna quorum_certificate_input
systemzax Sep 3, 2024
eca9352
Modified _check_qc function to accomodate optional weak QC verification
systemzax Sep 22, 2024
b4b47f8
Added support for combined weak/strong bitset comparison
systemzax Sep 30, 2024
1b743a3
Clean up
systemzax Sep 30, 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
108 changes: 73 additions & 35 deletions unittests/finality_proof.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,72 @@ namespace finality_proof {

// data relevant to IBC
struct ibc_block_data_t {
signed_block_ptr block;
signed_block_ptr block = nullptr;
qc_data_t qc_data;
action_trace onblock_trace;
finality_data_t finality_data;
uint32_t active_finalizer_policy_generation = 0;
uint32_t last_pending_finalizer_policy_generation = 0;
uint32_t last_proposed_finalizer_policy_generation = 0;
finalizer_policy active_finalizer_policy;
finalizer_policy last_pending_finalizer_policy;
finalizer_policy last_proposed_finalizer_policy;
digest_type action_mroot; //this is the real action_mroot, as returned from finality_data
digest_type base_digest;
digest_type active_finalizer_policy_digest;
digest_type last_pending_finalizer_policy_digest;
block_timestamp_type last_pending_finalizer_policy_start_timestamp;
digest_type last_proposed_finalizer_policy_digest;
digest_type finality_digest;
digest_type level_3_commitments_digest;
digest_type level_2_commitments_digest;
level_3_commitments_t level_3_commitments;
level_2_commitments_t level_2_commitments;
digest_type finality_leaf;
digest_type finality_root;
block_timestamp_type parent_timestamp;

digest_type level_3_commitments_digest() const {
return fc::sha256::hash(level_3_commitments);
}

digest_type level_2_commitments_digest() const {
return fc::sha256::hash(level_2_commitments);
}

};

inline std::string bitset_to_input_string(const boost::dynamic_bitset<unsigned char>& bitset) {
static const char* hexchar = "0123456789abcdef";

boost::dynamic_bitset<unsigned char> bs(bitset);
bs.resize((bs.size() + 7) & ~0x7);
assert(bs.size() % 8 == 0);

std::string result;
result.resize(bs.size() / 4);
for (size_t i = 0; i < bs.size(); i += 4) {
size_t x = 0;
for (size_t j = 0; j < 4; ++j)
x += bs[i+j] << j;
auto slot = i / 4;
result[slot % 2 ? slot - 1 : slot + 1] = hexchar[x]; // flip the two hex digits for each byte
}
return result;
}

inline std::string binary_to_hex(const std::string& bin) {
boost::dynamic_bitset<unsigned char> bitset(bin.size());
for (size_t i = 0; i < bin.size(); ++i) {
if (bin[i] == '1') {
bitset.set(bin.size() - 1 - i);
}
}
return bitset_to_input_string(bitset);
}

inline auto finalizers_string = [](const vote_bitset_t finalizers) {
return bitset_to_input_string(finalizers);
};
heifner marked this conversation as resolved.
Show resolved Hide resolved

static digest_type hash_pair(const digest_type& a, const digest_type& b) {
inline digest_type hash_pair(const digest_type& a, const digest_type& b) {
return fc::sha256::hash(std::pair<const digest_type&, const digest_type&>(a, b));
}

//generate a proof of inclusion for a node at index from a list of leaves
static std::vector<digest_type> generate_proof_of_inclusion(const std::vector<digest_type>& leaves, const size_t index) {
inline std::vector<digest_type> generate_proof_of_inclusion(const std::vector<digest_type>& leaves, const size_t index) {
auto _leaves = leaves;
auto _index = index;

Expand Down Expand Up @@ -70,7 +109,7 @@ namespace finality_proof {
}

//extract instant finality data from block header extension, as well as qc data from block extension
static qc_data_t extract_qc_data(const signed_block_ptr& b) {
inline qc_data_t extract_qc_data(const signed_block_ptr& b) {
assert(b);
auto hexts = b->validate_and_extract_header_extensions();
if (auto f_entry = hexts.find(finality_extension::extension_id()); f_entry != hexts.end()) {
Expand All @@ -87,7 +126,7 @@ namespace finality_proof {
return {};
}

static bool has_finalizer_policy_diffs(const signed_block_ptr& block){
inline bool has_finalizer_policy_diffs(const signed_block_ptr& block){

// extract new finalizer policy
finality_extension f_ext = block->extract_header_extension<finality_extension>();
Expand All @@ -96,7 +135,7 @@ namespace finality_proof {

}

static finalizer_policy update_finalizer_policy(const signed_block_ptr block, const finalizer_policy& current_policy){
inline finalizer_policy update_finalizer_policy(const signed_block_ptr block, const finalizer_policy& current_policy){

// extract new finalizer policy
finality_extension f_ext = block->extract_header_extension<finality_extension>();
Expand All @@ -115,8 +154,7 @@ namespace finality_proof {
int32_t blocks_since_proposed = 0;
};

template<size_t NUM_NODES>
class proof_test_cluster : public finality_test_cluster<NUM_NODES> {
class proof_test_cluster : public finality_test_cluster<4> {
public:

/*****
Expand Down Expand Up @@ -144,6 +182,8 @@ namespace finality_proof {
block_timestamp_type timestamp;
block_timestamp_type parent_timestamp;

std::vector<bool> vote_propagation = {1,1,1};

block_timestamp_type prev_last_pending_finalizer_policy_start_timestamp;

// counter to (optimistically) track internal policy changes
Expand All @@ -160,7 +200,7 @@ namespace finality_proof {
return {finality_leaves.begin(), finality_leaves.begin() + cutoff + 1};
}

ibc_block_data_t process_result(eosio::testing::produce_block_result_t result){
ibc_block_data_t process_result(const eosio::testing::produce_block_result_t& result){

heifner marked this conversation as resolved.
Show resolved Hide resolved
signed_block_ptr block = result.block;

Expand Down Expand Up @@ -216,30 +256,31 @@ namespace finality_proof {
blocks_since_proposed_policy[last_proposed_finalizer_policy_digest] = {last_proposed_finalizer_policy, 0};
}
}

//process votes
this->process_finalizer_votes(vote_propagation); //enough to reach quorum threshold

//process votes and collect / compute the IBC-relevant data
this->process_votes(1, this->num_needed_for_quorum); //enough to reach quorum threshold

// compute the IBC-relevant data
finality_data_t finality_data = *this->node0.control->head_finality_data();
digest_type action_mroot = finality_data.action_mroot;
digest_type base_digest = finality_data.base_digest;

// compute commitments used for proving finality violations
digest_type level_3_commitments_digest = fc::sha256::hash(level_3_commitments_t{
level_3_commitments_t lvl3_commitments {
.reversible_blocks_mroot = finality_data.reversible_blocks_mroot,
.latest_qc_claim_block_num = finality_data.latest_qc_claim_block_num,
.latest_qc_claim_finality_digest = finality_data.latest_qc_claim_finality_digest,
.latest_qc_claim_timestamp = finality_data.latest_qc_claim_timestamp,
.timestamp = timestamp,
.base_digest = base_digest
});
};

// compute commitments used for proving finalizer policy changes
digest_type level_2_commitments_digest = fc::sha256::hash(level_2_commitments_t{
level_2_commitments_t lvl2_commitments {
.last_pending_fin_pol_digest = last_pending_finalizer_policy_digest,
.last_pending_fin_pol_start_timestamp = last_pending_finalizer_policy_start_timestamp,
.l3_commitments_digest = level_3_commitments_digest
});
.l3_commitments_digest = fc::sha256::hash(lvl3_commitments)
};

// during IF transition, finality_root is always set to an empty digest
digest_type finality_root = digest_type();
Expand All @@ -252,7 +293,7 @@ namespace finality_proof {
.active_finalizer_policy_generation = is_genesis ? 1 : active_finalizer_policy.generation,
.last_pending_finalizer_policy_generation = is_genesis ? 1 : last_pending_finalizer_policy.generation,
.finality_tree_digest = finality_root,
.l2_commitments_digest = level_2_commitments_digest
.l2_commitments_digest = fc::sha256::hash(lvl2_commitments)
});

// compute finality leaf
Expand All @@ -278,18 +319,15 @@ namespace finality_proof {
.qc_data = qc_data,
.onblock_trace = onblock_trace,
.finality_data = finality_data,
.active_finalizer_policy_generation = active_finalizer_policy.generation,
.last_pending_finalizer_policy_generation = last_pending_finalizer_policy.generation,
.last_proposed_finalizer_policy_generation = last_proposed_finalizer_policy.generation,
.active_finalizer_policy = active_finalizer_policy,
.last_pending_finalizer_policy = last_pending_finalizer_policy,
.last_proposed_finalizer_policy = last_proposed_finalizer_policy,
.action_mroot = action_mroot,
.base_digest = base_digest,
.active_finalizer_policy_digest = active_finalizer_policy_digest,
.last_pending_finalizer_policy_digest = last_pending_finalizer_policy_digest,
.last_pending_finalizer_policy_start_timestamp = last_pending_finalizer_policy_start_timestamp,
.last_proposed_finalizer_policy_digest = last_proposed_finalizer_policy_digest,
.finality_digest = finality_digest,
.level_3_commitments_digest = level_3_commitments_digest,
.level_2_commitments_digest = level_2_commitments_digest,
.level_3_commitments = lvl3_commitments,
.level_2_commitments = lvl2_commitments,
.finality_leaf = finality_leaf,
.finality_root = finality_root ,
.parent_timestamp = parent_timestamp
Expand All @@ -312,7 +350,7 @@ namespace finality_proof {
}

proof_test_cluster(finality_cluster_config_t config = {.transition_to_savanna = false})
: finality_test_cluster<NUM_NODES>(config) {
: finality_test_cluster<4>(config) {

}

Expand Down
Loading