-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from LNP-BP/merklization
Merklization audit
- Loading branch information
Showing
7 changed files
with
199 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,20 @@ | |
// You should have received a copy of the Apache 2.0 License along with this | ||
// software. If not, see <https://opensource.org/licenses/Apache-2.0>. | ||
|
||
use commit_verify::stl; | ||
use strict_types::parse_args; | ||
use std::fs; | ||
use std::io::Write; | ||
|
||
use commit_verify::stl::commit_verify_stl; | ||
use commit_verify::{mpc, CommitmentLayout, MerkleNode}; | ||
use strict_types::stl::{std_stl, strict_types_stl}; | ||
use strict_types::{parse_args, SystemBuilder}; | ||
|
||
fn main() { | ||
let lib = stl::commit_verify_stl(); | ||
let lib = commit_verify_stl(); | ||
let (format, dir) = parse_args(); | ||
lib.serialize( | ||
format, | ||
dir, | ||
dir.as_ref(), | ||
"0.1.0", | ||
Some( | ||
" | ||
|
@@ -31,4 +36,56 @@ fn main() { | |
), | ||
) | ||
.expect("unable to write to the file"); | ||
|
||
let dir = dir.unwrap_or_else(|| ".".to_owned()); | ||
|
||
let std = std_stl(); | ||
let st = strict_types_stl(); | ||
let cv = commit_verify_stl(); | ||
|
||
let sys = SystemBuilder::new() | ||
.import(cv) | ||
.unwrap() | ||
.import(st) | ||
.unwrap() | ||
.import(std) | ||
.unwrap() | ||
.finalize() | ||
.expect("not all libraries present"); | ||
|
||
let mut file = fs::File::create(format!("{dir}/Merkle.vesper")).unwrap(); | ||
writeln!( | ||
file, | ||
"{{- | ||
Description: Merklization and MPC workflows | ||
Author: Dr Maxim Orlovsky <[email protected]> | ||
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved. | ||
License: Apache-2.0 | ||
-}} | ||
Merklization vesper lexicon=types+commitments | ||
" | ||
) | ||
.unwrap(); | ||
writeln!(file, "\n-- General merklization workflows\n").unwrap(); | ||
let layout = MerkleNode::commitment_layout(); | ||
writeln!(file, "{layout}").unwrap(); | ||
let tt = sys.type_tree("CommitVerify.MerkleNode").unwrap(); | ||
writeln!(file, "{tt}").unwrap(); | ||
|
||
writeln!(file, "\n-- Multi-protocol commitment workflows\n").unwrap(); | ||
let layout = mpc::Leaf::commitment_layout(); | ||
writeln!(file, "{layout}").unwrap(); | ||
let tt = sys.type_tree("CommitVerify.Leaf").unwrap(); | ||
writeln!(file, "{tt}").unwrap(); | ||
|
||
let layout = mpc::MerkleBlock::commitment_layout(); | ||
writeln!(file, "{layout}").unwrap(); | ||
let tt = sys.type_tree("CommitVerify.MerkleBlock").unwrap(); | ||
writeln!(file, "{tt}").unwrap(); | ||
|
||
let layout = mpc::MerkleTree::commitment_layout(); | ||
writeln!(file, "{layout}").unwrap(); | ||
let tt = sys.type_tree("CommitVerify.MerkleTree").unwrap(); | ||
writeln!(file, "{tt}").unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
DzTvt9gGhPUKD8Dkkjk9PDBhkJ4g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veO2zMB=|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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
{- | ||
Description: Merklization and MPC workflows | ||
Author: Dr Maxim Orlovsky <[email protected]> | ||
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved. | ||
License: Apache-2.0 | ||
-} | ||
|
||
Merklization vesper lexicon=types+commitments | ||
|
||
|
||
-- General merklization workflows | ||
|
||
MerkleHash commitment hasher=SHA256 tagged=urn:ubideco:merkle:node#2024-01-31 | ||
MerkleNode serialized | ||
|
||
MerkleNode rec | ||
branching enum void=0 single=1 branch=2 -- NodeBranching | ||
depth is U8 | ||
width is U256 | ||
node1 bytes len=32 aka=MerkleHash | ||
node2 bytes len=32 aka=MerkleHash | ||
|
||
|
||
-- Multi-protocol commitment workflows | ||
|
||
MerkleHash commitment hasher=SHA256 tagged=urn:ubideco:merkle:node#2024-01-31 | ||
Leaf serialized | ||
|
||
Leaf union | ||
inhabited rec tag=0 | ||
protocol bytes len=32 aka=ProtocolId | ||
message bytes len=32 aka=Message | ||
entropy rec tag=1 | ||
entropy is U64 | ||
pos is U32 | ||
|
||
Commitment commitment hasher=SHA256 tagged=urn:ubideco:mpc:commitment#2024-01-31 | ||
MerkleBlock concealed concealed=MerkleBlock | ||
|
||
MerkleBlock rec | ||
depth enum { | ||
_0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 _8=8 | ||
_9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 _16=16 | ||
_17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 _24=24 | ||
_25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 | ||
} -- U5 | ||
cofactor is U16 | ||
crossSection list len=1..MAX32 | ||
TreeNode union | ||
concealedNode rec tag=0 | ||
depth enum { | ||
_0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 _8=8 | ||
_9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 _16=16 | ||
_17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 _24=24 | ||
_25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 | ||
} -- U5 | ||
hash bytes len=32 aka=MerkleHash | ||
commitmentLeaf rec tag=1 | ||
protocolId bytes len=32 aka=ProtocolId | ||
message bytes len=32 aka=Message | ||
some is U64 option wrapped tag=1 | ||
|
||
Commitment commitment hasher=SHA256 tagged=urn:ubideco:mpc:commitment#2024-01-31 | ||
MerkleBlock concealed concealed=MerkleBlock | ||
|
||
MerkleTree rec | ||
depth enum { | ||
_0=0 _1=1 _2=2 _3=3 _4=4 _5=5 _6=6 _7=7 _8=8 | ||
_9=9 _10=10 _11=11 _12=12 _13=13 _14=14 _15=15 _16=16 | ||
_17=17 _18=18 _19=19 _20=20 _21=21 _22=22 _23=23 _24=24 | ||
_25=25 _26=26 _27=27 _28=28 _29=29 _30=30 _31=31 | ||
} -- U5 | ||
entropy is U64 | ||
cofactor is U16 | ||
messages map len=0..MAX24 | ||
key bytes len=32 aka=ProtocolId | ||
value bytes len=32 aka=Message | ||
map map len=0..MAX24 | ||
key is U32 | ||
value tuple | ||
_ bytes len=32 aka=ProtocolId | ||
_ bytes len=32 aka=Message | ||
|