Skip to content

Commit

Permalink
mpc: require MerkleBlock to contain a non-empty cross-section
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Feb 28, 2024
1 parent 5ae480c commit 8b5f9a0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
12 changes: 6 additions & 6 deletions commit_verify/src/mpc/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};

use amplify::confinement::{Confined, LargeVec};
use amplify::confinement::{Confined, NonEmptyVec, U32 as U32MAX};
use amplify::num::u5;
use strict_encoding::{StrictDeserialize, StrictDumb, StrictEncode, StrictSerialize};

Expand Down Expand Up @@ -148,7 +148,7 @@ pub struct MerkleBlock {

/// Tree cross-section.
#[getter(skip)]
cross_section: LargeVec<TreeNode>,
cross_section: NonEmptyVec<TreeNode, U32MAX>,

/// Entropy used for placeholders. May be unknown if the message is provided
/// by a third party, wishing to conceal that information.
Expand All @@ -161,7 +161,7 @@ impl StrictDumb for MerkleBlock {
MerkleBlock {
depth: u5::ONE,
cofactor: 0,
cross_section: confined_vec![TreeNode::strict_dumb()],
cross_section: NonEmptyVec::with(TreeNode::strict_dumb()),
entropy: Some(8845),
}
}
Expand All @@ -188,7 +188,7 @@ impl From<&MerkleTree> for MerkleBlock {
})
});
let cross_section =
LargeVec::try_from_iter(iter).expect("tree width guarantees are broken");
NonEmptyVec::try_from_iter(iter).expect("tree width guarantees are broken");

MerkleBlock {
depth: tree.depth,
Expand Down Expand Up @@ -248,7 +248,7 @@ impl MerkleBlock {
});
cross_section.extend(rev.into_iter().rev());
let cross_section =
LargeVec::try_from(cross_section).expect("tree width guarantees are broken");
NonEmptyVec::try_from(cross_section).expect("tree width guarantees are broken");

Ok(MerkleBlock {
depth: u5::with(path.len() as u8),
Expand Down Expand Up @@ -482,7 +482,7 @@ impl MerkleBlock {
cross_section.extend(b);

self.cross_section =
LargeVec::try_from(cross_section).expect("tree width guarantees are broken");
NonEmptyVec::try_from(cross_section).expect("tree width guarantees are broken");

assert_eq!(
self.cross_section
Expand Down
3 changes: 2 additions & 1 deletion commit_verify/src/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use strict_types::{CompileError, LibBuilder, TypeLib};
use crate::{mpc, MerkleHash, MerkleNode, StrictHash, LIB_NAME_COMMIT_VERIFY};

pub const LIB_ID_COMMIT_VERIFY: &str =
"urn:ubideco:stl:57sPvZcwQaziec3ux249XoCMhziQpKB8Yw99U5oRwfqW#deluxe-safari-random";
"urn:ubideco:stl:7qvjR4HCwJKF3mxE5GqsAaADces5JDRwb8ajAse9mkz3#exhibit-karate-ritual";

fn _commit_verify_stl() -> Result<TypeLib, CompileError> {
LibBuilder::new(libname!(LIB_NAME_COMMIT_VERIFY), tiny_bset! {
Expand All @@ -33,6 +33,7 @@ fn _commit_verify_stl() -> Result<TypeLib, CompileError> {
.transpile::<mpc::MerkleTree>()
.transpile::<mpc::MerkleBlock>()
.transpile::<mpc::MerkleProof>()
.transpile::<mpc::Leaf>()
.transpile::<mpc::Commitment>()
.transpile::<MerkleNode>()
.transpile::<MerkleHash>()
Expand Down
51 changes: 27 additions & 24 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
-----BEGIN STRICT TYPE LIB-----
Id: 57sPvZcwQaziec3ux249XoCMhziQpKB8Yw99U5oRwfqW#deluxe-safari-random
Id: 7qvjR4HCwJKF3mxE5GqsAaADces5JDRwb8ajAse9mkz3#exhibit-karate-ritual
Name: CommitVerify
Dependencies:
DzTvt9gGhPUKD8Dkkjk9PDBhkJ4gtWxXWQjxnmUYLNrs#voyage-kimono-disco

3`1{iZE18?WpZg|c>%!$%tl@;WNu_lcw-g2$nLVb<*lb*ENIx0;35YAw}=B%bYuY
oQ*>kj0A^Tl*p6J$36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k^)sV3jhj3Z*6U9bZu
pBbOiwb2LJ#-AOH(ZWpZn5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xv|61vo|<S$
`kJ6oIZx{|tq&1{dNqe!iO(;xhmM00000001BW00000000V2WpZn5WmIxyWd;QWW
My!4Xad0m%tl@;WNu_lcw-g2$nLVb<*lb*ENIx0;35YAw}@s~aM+Gq(Fu_0Ocz)^
+@GUUoV7w&pu=F9->y0X3z7$AZgg^QaCra#2nb_uW?^G=Z*l+t0tjtob8}&5Wpe-
u0Wg(*<{e=)S-S-Y<l(P9Y9YVY`}-X+f~R@qMRed+u>mzVsZkZk>V@1=_p5>Oab-
~jCR3C`SFec^=zG+gvC{wm0000000960{{R30000ARVQ>Hn000C41p)yum44<OVK
iC01qkHfuRUrZzt;Qv9WjEZdF4fP;8w8#H8-hI70Bv^+*0?ef%0)>Q3WPbltNdpi
4*91)SI!>0000000000|Ns90000002Tf&jb75y?1pxpD002NB01ZxWWMx8fVQyn+
X>Ml&0|a(&X=DHfb7^j8Y-IrkVsc?_V`u^jP;zf{Z)0z4Nn`~900#g7Kp+4LQ*?4
^V{}Mib7%zt00#g7Kp+4JRB~lyPH$vo1OfmJV{dL_WnpY(WKM5nWdH^O1!QG#bZ7
#>1k6TWEM#tEO?YD!yU6acy5+5>Uo2?YlHei-0Jn%{Sa8^mT+s=T=}Z?`J=~w8Q=
GLzSfImTncuED0}GM_Xkl|`0XUvRh9?yTI7S;;e;>sZfv!yd427@;7veO2zMB=|G
XV}`Z*6U9bZupBbWCMoW&j2P3UG37bZ=vCY)NDRFqMAh9bq(Cy9Eg3;jcYvA-~r9
`yDZYr+MW?bl_I82W@3@b75y?0W~+NQ5DGQh1^p2tAX-yWl;qtQ<OqiuZa`rd(@k
;(*

-----END STRICT TYPE LIB-----

Binary file modified stl/[email protected]
Binary file not shown.
10 changes: 7 additions & 3 deletions stl/[email protected]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{-
Id: urn:ubideco:stl:57sPvZcwQaziec3ux249XoCMhziQpKB8Yw99U5oRwfqW#deluxe-safari-random
Id: urn:ubideco:stl:7qvjR4HCwJKF3mxE5GqsAaADces5JDRwb8ajAse9mkz3#exhibit-karate-ritual
Name: CommitVerify
Version: 0.1.0
Description: Client-side-validation deterministic commitments
Expand All @@ -18,10 +18,14 @@ import Std#DzTvt9gGhPUKD8Dkkjk9PDBhkJ4gtWxXWQjxnmUYLNrs#voyage-kimono-disco
@mnemonic(ventura-equal-think)
data Commitment : [Byte ^ 32]

@mnemonic(iris-explore-script)
@mnemonic(pony-audio-mozart)
data Leaf : inhabited#16 (protocol ProtocolId, message Message)
| entropy (entropy U64, pos U32)

@mnemonic(owner-albert-lexicon)
data MerkleBlock : depth Std.U5#nitro-george-nebula
, cofactor U16
, crossSection [TreeNode ^ ..0xffffffff]
, crossSection [TreeNode ^ 1..0xffffffff]
, entropy U64?

@mnemonic(culture-metro-modular)
Expand Down

0 comments on commit 8b5f9a0

Please sign in to comment.