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

Savanna IBC tests improvements #136

Merged
merged 24 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b6a4e45
refactored svnn_ibc_tests in prepartion for finalizer policy change test
systemzax May 8, 2024
6e3b26e
Restructured svnn_ibc test
systemzax May 13, 2024
1133abd
Updated svnn_ibc test to match new finalizer policy diffs
systemzax May 13, 2024
006e17e
Updated to reflect updated finality digest computation + added test f…
systemzax May 13, 2024
74e584a
Completed new finalizer policy proof
systemzax May 13, 2024
da7f956
Re-enabled cache + garbage collection test
systemzax May 13, 2024
60b5998
Added savanna_witness_hash() intermediate digest function to action t…
systemzax May 13, 2024
c10f180
Cleaned up ibc smart contract code
systemzax May 13, 2024
16c68f3
Cleaned up ibc smart contract code
systemzax May 13, 2024
945c802
Minor edit to comment + removed extra lines
systemzax May 13, 2024
e8cdafc
Removed print statements in contract, recompiled
systemzax May 13, 2024
ac55e2d
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 13, 2024
3d794dd
Merge branch 'main' of https://github.com/antelopeIO/spring
systemzax May 13, 2024
82a5e33
Updated chainbase submodule reference
systemzax May 13, 2024
fb2578b
Manual merge
systemzax May 13, 2024
5bcf271
Changed finality_digest_data_v1 struct member name to match updated (…
systemzax May 13, 2024
480125f
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 13, 2024
b897d93
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 15, 2024
898143e
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 15, 2024
7ccb9a2
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 16, 2024
f159f98
Decreased the ibc contract default cache duration to 5 seconds to min…
systemzax May 17, 2024
f33334a
Recompiled contract
systemzax May 17, 2024
8cd5ea6
Fixed misc issues
systemzax May 17, 2024
dbba203
Merge branch 'main' into svnn_ibc_tests_improvements
systemzax May 17, 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
23 changes: 15 additions & 8 deletions libraries/chain/include/eosio/chain/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ namespace eosio::chain {
std::optional<uint64_t> error_code;
std::vector<char> return_value;

//savanna_witness_hash can be computed separately, since it is not relevant to IBC action proofs
digest_type savanna_witness_hash() const {
assert(!!receipt);
const action_receipt& r = *receipt;

digest_type::encoder e;
fc::raw::pack(e, r.global_sequence);
fc::raw::pack(e, r.auth_sequence);
fc::raw::pack(e, r.code_sequence);
fc::raw::pack(e, r.abi_sequence);

return e.result();
}

digest_type digest_savanna() const {
assert(!!receipt);
const action_receipt& r = *receipt;
Expand All @@ -56,15 +70,8 @@ namespace eosio::chain {
fc::raw::pack(e, act.account);
fc::raw::pack(e, act.name);
fc::raw::pack(e, r.act_digest);
fc::raw::pack(e, savanna_witness_hash());

{
digest_type::encoder e2;
fc::raw::pack(e2, r.global_sequence);
fc::raw::pack(e2, r.auth_sequence);
fc::raw::pack(e2, r.code_sequence);
fc::raw::pack(e2, r.abi_sequence);
fc::raw::pack(e, e2.result());
}
return e.result();
}

Expand Down
7 changes: 7 additions & 0 deletions unittests/finality_test_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ class finality_test_cluster {
return b;
}

eosio::testing::produce_block_result_t produce_and_push_block_ex() {
auto b = node0.produce_block_ex();
for (size_t i=1; i<nodes.size(); ++i)
nodes[i].push_block(b.block);
return b;
}

// Produces a number of blocks and returns true if LIB is advancing.
// This function can be only used at the end of a test as it clears
// node1 to nodeN votes when starting.
Expand Down
712 changes: 570 additions & 142 deletions unittests/svnn_ibc_tests.cpp

Large diffs are not rendered by default.

96 changes: 52 additions & 44 deletions unittests/test-contracts/svnn_ibc/svnn_ibc.abi
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,57 @@
"version": "eosio::abi/1.2",
"types": [],
"structs": [
{
"name": "action",
"base": "action_base",
"fields": [
{
"name": "data",
"type": "bytes"
},
{
"name": "return_value",
"type": "bytes"
}
]
},
{
"name": "action_base",
"base": "",
"fields": [
{
"name": "account",
"type": "name"
},
{
"name": "name",
"type": "name"
},
{
"name": "authorization",
"type": "permission_level[]"
}
]
},
{
"name": "action_data",
"base": "",
"fields": [
{
"name": "action",
"type": "r_action"
"type": "action"
},
{
"name": "action_receipt_digest",
"type": "checksum256"
"name": "receiver",
"type": "name"
},
{
"name": "return_value",
"type": "bytes"
"name": "recv_sequence",
"type": "uint64"
},
{
"name": "witness_hash",
"type": "checksum256"
}
]
},
Expand Down Expand Up @@ -74,8 +110,8 @@
"type": "uint32"
},
{
"name": "active_finalizer_policy",
"type": "fpolicy?"
"name": "new_finalizer_policy",
"type": "finalizer_policy_input?"
},
{
"name": "witness_hash",
Expand Down Expand Up @@ -116,6 +152,10 @@
{
"name": "proof",
"type": "proof"
},
{
"name": "assert",
"type": "bool"
}
]
},
Expand Down Expand Up @@ -152,7 +192,7 @@
]
},
{
"name": "finalizer_authority",
"name": "finalizer_authority_input",
"base": "",
"fields": [
{
Expand All @@ -170,7 +210,7 @@
]
},
{
"name": "fpolicy",
"name": "finalizer_policy_input",
"base": "",
"fields": [
{
Expand All @@ -183,7 +223,7 @@
},
{
"name": "finalizers",
"type": "finalizer_authority[]"
"type": "finalizer_authority_input[]"
}
]
},
Expand Down Expand Up @@ -247,45 +287,13 @@
}
]
},
{
"name": "r_action",
"base": "r_action_base",
"fields": [
{
"name": "data",
"type": "bytes"
},
{
"name": "returnvalue",
"type": "bytes"
}
]
},
{
"name": "r_action_base",
"base": "",
"fields": [
{
"name": "account",
"type": "name"
},
{
"name": "name",
"type": "name"
},
{
"name": "authorization",
"type": "permission_level[]"
}
]
},
{
"name": "setfpolicy",
"base": "",
"fields": [
{
"name": "policy",
"type": "fpolicy"
"type": "finalizer_policy_input"
},
{
"name": "from_block_num",
Expand All @@ -295,7 +303,7 @@
},
{
"name": "storedpolicy",
"base": "fpolicy",
"base": "finalizer_policy_input",
"fields": [
{
"name": "last_block_num",
Expand Down
17 changes: 10 additions & 7 deletions unittests/test-contracts/svnn_ibc/svnn_ibc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bls_g1 svnn_ibc::_g1add(const bls_g1& op1, const bls_g1& op2) {
return r;
}

void svnn_ibc::_maybe_set_finalizer_policy(const fpolicy& policy, const uint32_t from_block_num){
void svnn_ibc::_maybe_set_finalizer_policy(const finalizer_policy_input& policy, const uint32_t from_block_num){
policies_table _policies_table(get_self(), get_self().value);
auto itr = _policies_table.rbegin();
//if the new policy is more recent than the most recent we are aware of, we record the new one
Expand Down Expand Up @@ -86,7 +86,7 @@ void svnn_ibc::_maybe_remove_from_cache(){

//verify that a signature over a given message has been generated with the private key matching the public key
void svnn_ibc::_verify(const std::string& public_key, const std::string& signature, const std::string& message){
check(bls_signature_verify(decode_bls_public_key_to_g1(public_key), decode_bls_signature_to_g2(signature), message), "signature verify failed");
check(bls_signature_verify(decode_bls_public_key_to_g1(public_key), decode_bls_signature_to_g2(signature), message), "signature verification failed");
}

//verify that the quorum certificate over the finality digest is valid
Expand Down Expand Up @@ -149,8 +149,8 @@ void svnn_ibc::_check_target_block_proof_of_inclusion(const block_proof_of_inclu
check(itr!= merkle_index.end(), "cannot link proof to proven merkle root");
}
//block_data target_block = std::get<svnn_ibc::block_data>(proof.target);
if (proof.target.finality_data.active_finalizer_policy.has_value()){
_maybe_set_finalizer_policy(proof.target.finality_data.active_finalizer_policy.value(), proof.target.dynamic_data.block_num);
if (proof.target.finality_data.new_finalizer_policy.has_value()){
_maybe_set_finalizer_policy(proof.target.finality_data.new_finalizer_policy.value(), proof.target.dynamic_data.block_num);
}
}

Expand All @@ -167,24 +167,25 @@ void svnn_ibc::_check_finality_proof(const finality_proof& finality_proof, const
_maybe_add_proven_root(target_block_proof_of_inclusion.target.dynamic_data.block_num + offset, finality_proof.qc_block.finality_mroot);
}

ACTION svnn_ibc::setfpolicy(const fpolicy& policy, const uint32_t from_block_num){
ACTION svnn_ibc::setfpolicy(const finalizer_policy_input& policy, const uint32_t from_block_num){

//can only be called with account authority
require_auth(get_self());

policies_table _policies_table(get_self(), get_self().value);

//can only be used once for the initilization of the contract
check(_policies_table.begin() == _policies_table.end(), "can only set finalizer policy manually for initialization");
//check(_policies_table.begin() == _policies_table.end(), "can only set finalizer policy manually for initialization");

_maybe_set_finalizer_policy(policy, from_block_num);

//clean up if necessary
_maybe_remove_from_cache<policies_table>();
_maybe_remove_from_cache<proofs_table>();

}

ACTION svnn_ibc::checkproof(const proof& proof){
ACTION svnn_ibc::checkproof(const proof& proof, const bool assert){

//if we have a finality proof, we execute the "heavy" code path
if (proof.finality_proof.has_value()){
Expand All @@ -199,4 +200,6 @@ ACTION svnn_ibc::checkproof(const proof& proof){
_maybe_remove_from_cache<policies_table>();
_maybe_remove_from_cache<proofs_table>();

check(!assert, "expected");

}
Loading
Loading