From 8b5f9a02bdb2f8790736515d49369b7129f9f107 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Wed, 28 Feb 2024 11:07:42 +0100 Subject: [PATCH] mpc: require MerkleBlock to contain a non-empty cross-section --- commit_verify/src/mpc/block.rs | 12 ++++---- commit_verify/src/stl.rs | 3 +- stl/CommitVerify@0.1.0.sta | 51 +++++++++++++++++---------------- stl/CommitVerify@0.1.0.stl | Bin 1199 -> 1333 bytes stl/CommitVerify@0.1.0.sty | 10 +++++-- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/commit_verify/src/mpc/block.rs b/commit_verify/src/mpc/block.rs index 630937cc..5acb27c0 100644 --- a/commit_verify/src/mpc/block.rs +++ b/commit_verify/src/mpc/block.rs @@ -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}; @@ -148,7 +148,7 @@ pub struct MerkleBlock { /// Tree cross-section. #[getter(skip)] - cross_section: LargeVec, + cross_section: NonEmptyVec, /// Entropy used for placeholders. May be unknown if the message is provided /// by a third party, wishing to conceal that information. @@ -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), } } @@ -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, @@ -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), @@ -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 diff --git a/commit_verify/src/stl.rs b/commit_verify/src/stl.rs index 858d8a42..1240f76b 100644 --- a/commit_verify/src/stl.rs +++ b/commit_verify/src/stl.rs @@ -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 { LibBuilder::new(libname!(LIB_NAME_COMMIT_VERIFY), tiny_bset! { @@ -33,6 +33,7 @@ fn _commit_verify_stl() -> Result { .transpile::() .transpile::() .transpile::() + .transpile::() .transpile::() .transpile::() .transpile::() diff --git a/stl/CommitVerify@0.1.0.sta b/stl/CommitVerify@0.1.0.sta index 274f691d..d055d5b6 100644 --- a/stl/CommitVerify@0.1.0.sta +++ b/stl/CommitVerify@0.1.0.sta @@ -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*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