Skip to content

Commit 53bb7ea

Browse files
authored
Add tree hash to tree operations test vectors (#352)
* Add tree hash to test vector structs * Reflect changes in JSON serialization * Set ciphersuite and initialize tree
1 parent df37cd6 commit 53bb7ea

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

cmd/interop/src/json_details.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,13 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(WelcomeTestVector,
290290
welcome)
291291

292292
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(TreeOperationsTestVector,
293+
cipher_suite,
293294
tree_before,
295+
tree_hash_before,
294296
proposal,
295297
proposal_sender,
296-
tree_after)
298+
tree_after,
299+
tree_hash_after)
297300

298301
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(TreeKEMTestVector::PathSecret,
299302
node,

lib/mls_vectors/include/mls_vectors/mls_vectors.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,15 +444,20 @@ struct TreeOperationsTestVector : PseudoRandom
444444

445445
static const std::vector<Scenario> all_scenarios;
446446

447+
mls::CipherSuite cipher_suite;
448+
447449
mls::TreeKEMPublicKey tree_before;
450+
bytes tree_hash_before;
451+
448452
mls::Proposal proposal;
449453
mls::LeafIndex proposal_sender;
450454

451455
mls::TreeKEMPublicKey tree_after;
456+
bytes tree_hash_after;
452457

453458
TreeOperationsTestVector() = default;
454459
TreeOperationsTestVector(mls::CipherSuite suite, Scenario scenario);
455-
std::optional<std::string> verify() const;
460+
std::optional<std::string> verify();
456461
};
457462

458463
struct TreeKEMTestVector : PseudoRandom

lib/mls_vectors/src/mls_vectors.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ const std::vector<TreeOperationsTestVector::Scenario>
14511451
TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
14521452
Scenario scenario)
14531453
: PseudoRandom(suite, "tree-operations")
1454+
, cipher_suite(suite)
14541455
, proposal_sender(0)
14551456
{
14561457
auto init_priv = prg.hpke_key("init_key");
@@ -1480,6 +1481,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
14801481
proposal = Proposal{ Add{ key_package } };
14811482

14821483
tree_before = tc.pub;
1484+
tree_hash_before = tree_before.root_hash();
14831485

14841486
tree_after = tree_before;
14851487
tree_after.add_leaf(key_package.leaf_node);
@@ -1493,6 +1495,8 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
14931495

14941496
tree_before = tc.pub;
14951497
tree_before.blank_path(LeafIndex{ 4 });
1498+
tree_before.set_hash_all();
1499+
tree_hash_before = tree_before.root_hash();
14961500

14971501
tree_after = tree_before;
14981502
tree_after.add_leaf(key_package.leaf_node);
@@ -1506,6 +1510,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15061510
proposal = Proposal{ Update{ key_package.leaf_node } };
15071511

15081512
tree_before = tc.pub;
1513+
tree_hash_before = tree_before.root_hash();
15091514

15101515
tree_after = tree_before;
15111516
tree_after.update_leaf(proposal_sender, key_package.leaf_node);
@@ -1519,6 +1524,7 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15191524
proposal = Proposal{ Remove{ removed } };
15201525

15211526
tree_before = tc.pub;
1527+
tree_hash_before = tree_before.root_hash();
15221528

15231529
tree_after = tree_before;
15241530
tree_after.blank_path(removed);
@@ -1533,19 +1539,28 @@ TreeOperationsTestVector::TreeOperationsTestVector(mls::CipherSuite suite,
15331539
proposal = Proposal{ Remove{ removed } };
15341540

15351541
tree_before = tc.pub;
1542+
tree_hash_before = tree_before.root_hash();
15361543

15371544
tree_after = tree_before;
15381545
tree_after.blank_path(removed);
15391546
tree_after.truncate();
15401547
break;
15411548
}
15421549
}
1550+
1551+
tree_after.set_hash_all();
1552+
tree_hash_after = tree_after.root_hash();
15431553
}
15441554

15451555
std::optional<std::string>
1546-
TreeOperationsTestVector::verify() const
1556+
TreeOperationsTestVector::verify()
15471557
{
1558+
tree_before.suite = cipher_suite;
1559+
tree_before.set_hash_all();
1560+
15481561
auto tree = tree_before;
1562+
VERIFY_EQUAL("tree hash before", tree.root_hash(), tree_hash_before);
1563+
15491564
auto apply = overloaded{
15501565
[&](const Add& add) { tree.add_leaf(add.key_package.leaf_node); },
15511566

@@ -1566,6 +1581,9 @@ TreeOperationsTestVector::verify() const
15661581
var::visit(apply, proposal.content);
15671582
VERIFY_EQUAL("tree after", tree, tree_after);
15681583

1584+
tree.set_hash_all();
1585+
VERIFY_EQUAL("tree hash after", tree.root_hash(), tree_hash_after);
1586+
15691587
return std::nullopt;
15701588
}
15711589

0 commit comments

Comments
 (0)