Skip to content

Commit

Permalink
Merge branch 'main' into ext-sender-proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
bifurcation committed Aug 21, 2024
2 parents 2831911 + fd3fc39 commit f19d34d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/treekem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,18 +903,19 @@ TreeKEMPublicKey::parent_hashes(
}

// The list of nodes for whom parent hashes are computed, namely: Direct path
// excluding root, including leaf
// excluding the last entry, including leaf
auto from_node = NodeIndex(from);
auto dp = fdp;
auto [last, _res_last] = dp.back();
dp.pop_back();
dp.insert(dp.begin(), { from_node, {} });

if (dp.size() != path_nodes.size()) {
throw ProtocolError("Malformed UpdatePath");
}

// Parent hash for all the parents, starting from the root
auto last = NodeIndex::root(size);
// Parent hash for all the parents, starting from the last entry of the
// filtered direct path
auto last_hash = bytes{};
auto ph = std::vector<bytes>(dp.size());
for (int i = static_cast<int>(dp.size()) - 1; i >= 0; i--) {
Expand Down
47 changes: 46 additions & 1 deletion test/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,51 @@ TEST_CASE_METHOD(RelatedGroupTest, "Reinitialize the group")
}
}

TEST_CASE_METHOD(StateTest, "Parent Hash with Empty Left Subtree")
{
// Create a group with 4 members
auto state_0 = State(group_id,
suite,
leaf_privs[0],
identity_privs[0],
key_packages[0].leaf_node,
ExtensionList{});

const auto adds = std::vector{
state_0.add_proposal(key_packages[1]),
state_0.add_proposal(key_packages[2]),
state_0.add_proposal(key_packages[3]),
};

auto [_commit0, welcome0, new_state_0] =
state_0.commit(fresh_secret(), CommitOpts{ adds, true, false, {} }, {});
silence_unused(_commit0);
state_0 = new_state_0;

auto state_2 = State(init_privs[2],
leaf_privs[2],
identity_privs[2],
key_packages[2],
welcome0,
std::nullopt,
{});
// Member @2 removes the members on the left side of the tree
const auto removes = std::vector{
state_2.remove_proposal(LeafIndex{ 0 }),
state_2.remove_proposal(LeafIndex{ 1 }),
};

auto [commit2, welcome2, new_state_2] =
state_2.commit(fresh_secret(), CommitOpts{ removes, true, false, {} }, {});
silence_unused(commit2);
silence_unused(welcome2);
state_2 = new_state_2;

// Member @2 should have a valid tree, even though its filtered direct path no
// longer goes to the root.
REQUIRE(state_2.tree().parent_hash_valid());
}

class ExternalSenderTest : public StateTest
{
protected:
Expand Down Expand Up @@ -1217,4 +1262,4 @@ TEST_CASE_METHOD(ExternalSenderTest,

REQUIRE_THROWS_WITH(states[0].handle(external_init_message),
"Invalid external proposal");
}
}

0 comments on commit f19d34d

Please sign in to comment.