-
-
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.
stl: generate vesper file for merklization workflows
- Loading branch information
1 parent
8b5f9a0
commit b7b6aaf
Showing
2 changed files
with
144 additions
and
4 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
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 | ||
|