Skip to content

Commit

Permalink
Merge pull request #76 from BP-WG/layouts
Browse files Browse the repository at this point in the history
Commitment layouts for DBCs
  • Loading branch information
dr-orlovsky authored Feb 26, 2024
2 parents 19cf59a + e15d688 commit 2f4bf12
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 45 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ wasm-bindgen-test = "0.3"
features = [ "all" ]

[patch.crates-io]
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "v0.11" }
strict_types = { git = "https://github.com/strict-types/strict-types", branch = "vesper" }
commit_verify = { git = "https://github.com/LNP-BP/client_side_validation", branch = "layouts" }
34 changes: 30 additions & 4 deletions src/bin/bpcore-stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
// limitations under the License.

use std::fs;
use std::io::Write;

use bc::stl::{bp_consensus_stl, bp_tx_stl};
use bp::stl::bp_core_stl;
use commit_verify::stl::commit_verify_stl;
use commit_verify::CommitmentLayout;
use seals::txout::{ChainBlindSeal, CloseMethod, SingleBlindSeal};
use strict_encoding::libname;
use strict_types::stl::std_stl;
use strict_types::{parse_args, SystemBuilder};
Expand Down Expand Up @@ -96,19 +99,42 @@ fn main() {

let dir = dir.unwrap_or_else(|| ".".to_owned());

let mut file = fs::File::create(format!("{dir}/Seals.vesper")).unwrap();
writeln!(
file,
"{{-
Description: Bitcoin TxO2 blind seals
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved.
License: Apache-2.0
-}}
Seals vesper lexicon=types+commitments
"
)
.unwrap();
let layout = SingleBlindSeal::<CloseMethod>::commitment_layout();
writeln!(file, "{layout}").unwrap();
let layout = ChainBlindSeal::<CloseMethod>::commitment_layout();
writeln!(file, "{layout}").unwrap();
let tt = sys.type_tree("BPCore.BlindSealTxid").unwrap();
writeln!(file, "{tt}").unwrap();
let tt = sys.type_tree("BPCore.BlindSealTxPtr").unwrap();
writeln!(file, "{tt}").unwrap();

let tt = sys.type_tree("BPCore.AnchorMerkleTreeTapretProof").unwrap();
fs::write(format!("{dir}/Anchor.MerkleTree.Tapret.vesper",), format!("{tt}")).unwrap();
fs::write(format!("{dir}/Anchor.MerkleTree.Tapret.vesper"), format!("{tt}")).unwrap();

let tt = sys.type_tree("BPCore.AnchorMerkleTreeOpretProof").unwrap();
fs::write(format!("{dir}/Anchor.MerkleTree.Opret.vesper",), format!("{tt}")).unwrap();
fs::write(format!("{dir}/Anchor.MerkleTree.Opret.vesper"), format!("{tt}")).unwrap();

let tt = sys
.type_tree("BPCore.AnchorMerkleBlockTapretProof")
.unwrap();
fs::write(format!("{dir}/Anchor.MerkleBlock.Tapret.vesper",), format!("{tt}")).unwrap();
fs::write(format!("{dir}/Anchor.MerkleBlock.Tapret.vesper"), format!("{tt}")).unwrap();

let tt = sys
.type_tree("BPCore.AnchorMerkleProofTapretProof")
.unwrap();
fs::write(format!("{dir}/Anchor.MerkleProof.Tapret.vesper",), format!("{tt}")).unwrap();
fs::write(format!("{dir}/Anchor.MerkleProof.Tapret.vesper"), format!("{tt}")).unwrap();

Check warning on line 139 in src/bin/bpcore-stl.rs

View check run for this annotation

Codecov / codecov/patch

src/bin/bpcore-stl.rs#L82-L139

Added lines #L82 - L139 were not covered by tests
}
32 changes: 17 additions & 15 deletions stl/Anchor.MerkleBlock.Tapret.vesper
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
AnchorMerkleBlockTapretProof rec
txid bytes len=32 aka=Txid
mpcProof rec -- MerkleBlock
mpcProof rec MerkleBlock
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
U5 _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

}
cofactor is U16
crossSection list len=0..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
U5 _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

}
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
dbcProof rec -- TapretProof
pathProof rec -- TapretPathProof
some union option wrapped tag=1 -- TapretNodePartner
rightBranch rec wrapped tag=2 -- TapretRightBranch
dbcProof rec TapretProof
pathProof rec TapretPathProof
some union TapretNodePartner option wrapped tag=1
rightBranch rec TapretRightBranch wrapped tag=2
nonce is U8
10 changes: 5 additions & 5 deletions stl/Anchor.MerkleProof.Tapret.vesper
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
AnchorMerkleProofTapretProof rec
txid bytes len=32 aka=Txid
mpcProof rec -- MerkleProof
mpcProof rec MerkleProof
pos is U32
cofactor is U16
path list len=0..32
element bytes len=32 aka=MerkleHash
dbcProof rec -- TapretProof
pathProof rec -- TapretPathProof
some union option wrapped tag=1 -- TapretNodePartner
rightBranch rec wrapped tag=2 -- TapretRightBranch
dbcProof rec TapretProof
pathProof rec TapretPathProof
some union TapretNodePartner option wrapped tag=1
rightBranch rec TapretRightBranch wrapped tag=2
nonce is U8
13 changes: 7 additions & 6 deletions stl/Anchor.MerkleTree.Opret.vesper
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
AnchorMerkleTreeOpretProof rec
txid bytes len=32 aka=Txid
mpcProof rec -- MerkleTree
mpcProof rec MerkleTree
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
U5 _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

}
entropy is U64
cofactor is U16
messages map len=0..MAX24
Expand Down
21 changes: 11 additions & 10 deletions stl/Anchor.MerkleTree.Tapret.vesper
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
AnchorMerkleTreeTapretProof rec
txid bytes len=32 aka=Txid
mpcProof rec -- MerkleTree
mpcProof rec MerkleTree
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
U5 _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

}
entropy is U64
cofactor is U16
messages map len=0..MAX24
Expand All @@ -17,8 +18,8 @@ AnchorMerkleTreeTapretProof rec
value tuple
_ bytes len=32 aka=ProtocolId
_ bytes len=32 aka=Message
dbcProof rec -- TapretProof
pathProof rec -- TapretPathProof
some union option wrapped tag=1 -- TapretNodePartner
rightBranch rec wrapped tag=2 -- TapretRightBranch
dbcProof rec TapretProof
pathProof rec TapretPathProof
some union TapretNodePartner option wrapped tag=1
rightBranch rec TapretRightBranch wrapped tag=2
nonce is U8
29 changes: 29 additions & 0 deletions stl/Seals.vesper
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{-
Description: Bitcoin TxO2 blind seals
Author: Dr Maxim Orlovsky <[email protected]>
Copyright (C) 2024 LNP/BP Standards Association. All rights reserved.
License: Apache-2.0
-}

Seals vesper lexicon=types+commitments

SecretSeal commitment hasher=SHA256 tagged=urn:lnp-bp:seals:secret#2024-02-03
BlindSealTxid serialized

SecretSeal commitment hasher=SHA256 tagged=urn:lnp-bp:seals:secret#2024-02-03
BlindSealTxPtr serialized

BlindSealTxid rec
method enum Method opretFirst=0 tapretFirst=1
txid bytes len=32 aka=Txid
vout is U32 aka=Vout
blinding is U64

BlindSealTxPtr rec
method enum Method opretFirst=0 tapretFirst=1
txid union TxPtr
witnessTx is Unit tag=0
txid bytes len=32 wrapped aka=Txid tag=1
vout is U32 aka=Vout
blinding is U64

0 comments on commit 2f4bf12

Please sign in to comment.