Skip to content

Commit 265a44e

Browse files
committed
Merge #264: Virtual hidden nodes
29dd9ea refactor: Remove Error::DisconnectCommitTime (Christian Lewe) cdf28e0 refactor: Simplify policy satisfier (Christian Lewe) ba5c7ef fix: Handle missing assembly fragments (Christian Lewe) d79c6bc feat: Add Hiding node (Christian Lewe) 776b23c feat: Add HasCmr trait (Christian Lewe) 7d862b8 fix: Update fuzz CI (Christian Lewe) Pull request description: This PR adds the wrapper type `Hiding<N>` which allows the use of hidden nodes during the construction of a program. The hidden nodes exist only in the wrapper and the `Inner` struct remains untouched _(therefore "virtual hidden nodes")_. We use `Hiding<N>` to simplify the policy satisfier and to represent missing assembly fragments, which removes one error path. ACKs for top commit: apoelstra: ACK 29dd9ea; successfully ran local tests; awesome, thanks! Tree-SHA512: 1ea6d93cfdbfb8af91b7702debf66c36354dc19c54efd36db49c81ee5bc55d227056914b44e158431021ab3d51771a2becb5380aea1ed5fc367b16d226b6b423
2 parents ca0c0eb + 29dd9ea commit 265a44e

File tree

8 files changed

+400
-154
lines changed

8 files changed

+400
-154
lines changed

.github/workflows/fuzz.yml

+31-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
fuzz:
13+
name: Run Fuzz Target
1314
if: ${{ !github.event.act }}
1415
runs-on: ubuntu-latest
1516
strategy:
@@ -24,36 +25,55 @@ parse_human,
2425
steps:
2526
- name: Install test dependencies
2627
run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
27-
- uses: actions/checkout@v4
28-
- uses: actions/cache@v3
28+
29+
- name: Checkout Crate
30+
uses: actions/checkout@v4
31+
32+
- name: Use Rust Cache
33+
uses: actions/cache@v4
2934
id: cache-fuzz
3035
with:
3136
path: |
3237
~/.cargo/bin
3338
fuzz/target
3439
target
3540
key: cache-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
36-
- uses: dtolnay/rust-toolchain@stable
41+
- name: Install Toolchain
42+
uses: dtolnay/rust-toolchain@stable
3743
with:
3844
toolchain: '1.65.0'
39-
- name: fuzz
45+
46+
- name: Run Fuzz Target
4047
run: |
4148
echo "Using RUSTFLAGS $RUSTFLAGS"
4249
cd fuzz && cargo update && cargo update -p cc --precise 1.0.83 && ./fuzz.sh "${{ matrix.fuzz_target }}"
43-
- run: echo "${{ matrix.fuzz_target }}" >executed_${{ matrix.fuzz_target }}
44-
- uses: actions/upload-artifact@v3
50+
51+
- name: Prepare Artifact
52+
run: echo "${{ matrix.fuzz_target }}" >executed_${{ matrix.fuzz_target }}
53+
54+
- name: Upload Artifact
55+
uses: actions/upload-artifact@v4
4556
with:
4657
name: executed_${{ matrix.fuzz_target }}
4758
path: executed_${{ matrix.fuzz_target }}
4859

4960
verify-execution:
61+
name: Verify Execution of All Targets
5062
if: ${{ !github.event.act }}
5163
needs: fuzz
5264
runs-on: ubuntu-latest
5365
steps:
54-
- uses: actions/checkout@v4
55-
- uses: actions/download-artifact@v3
56-
- name: Display structure of downloaded files
66+
- name: Checkout Crate
67+
uses: actions/checkout@v4
68+
69+
- name: Download All Artifacts
70+
uses: actions/download-artifact@v4
71+
72+
- name: Display Structure of Downloaded Files
5773
run: ls -R
58-
- run: find executed_* -type f -exec cat {} + | sort > executed
59-
- run: source ./fuzz/fuzz-util.sh && listTargetNames | sort | diff - executed
74+
75+
- name: Write File With All Executed Targets
76+
run: find executed_* -type f -exec cat {} + | sort > executed
77+
78+
- name: Compare Executed Targets With Available Targets
79+
run: source ./fuzz/fuzz-util.sh && listTargetNames | sort | diff - executed

fuzz/generate-files.sh

+31-11
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ on:
4949
5050
jobs:
5151
fuzz:
52+
name: Run Fuzz Target
5253
if: \${{ !github.event.act }}
5354
runs-on: ubuntu-latest
5455
strategy:
@@ -60,37 +61,56 @@ $(for name in $(listTargetNames); do echo "$name,"; done)
6061
steps:
6162
- name: Install test dependencies
6263
run: sudo apt-get update -y && sudo apt-get install -y binutils-dev libunwind8-dev libcurl4-openssl-dev libelf-dev libdw-dev cmake gcc libiberty-dev
63-
- uses: actions/checkout@v4
64-
- uses: actions/cache@v3
64+
65+
- name: Checkout Crate
66+
uses: actions/checkout@v4
67+
68+
- name: Use Rust Cache
69+
uses: actions/cache@v4
6570
id: cache-fuzz
6671
with:
6772
path: |
6873
~/.cargo/bin
6974
fuzz/target
7075
target
7176
key: cache-\${{ matrix.target }}-\${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
72-
- uses: dtolnay/rust-toolchain@stable
77+
- name: Install Toolchain
78+
uses: dtolnay/rust-toolchain@stable
7379
with:
7480
toolchain: '1.65.0'
75-
- name: fuzz
81+
82+
- name: Run Fuzz Target
7683
run: |
7784
echo "Using RUSTFLAGS \$RUSTFLAGS"
7885
cd fuzz && cargo update && cargo update -p cc --precise 1.0.83 && ./fuzz.sh "\${{ matrix.fuzz_target }}"
79-
- run: echo "\${{ matrix.fuzz_target }}" >executed_\${{ matrix.fuzz_target }}
80-
- uses: actions/upload-artifact@v3
86+
87+
- name: Prepare Artifact
88+
run: echo "\${{ matrix.fuzz_target }}" >executed_\${{ matrix.fuzz_target }}
89+
90+
- name: Upload Artifact
91+
uses: actions/upload-artifact@v4
8192
with:
8293
name: executed_\${{ matrix.fuzz_target }}
8394
path: executed_\${{ matrix.fuzz_target }}
8495
8596
verify-execution:
97+
name: Verify Execution of All Targets
8698
if: \${{ !github.event.act }}
8799
needs: fuzz
88100
runs-on: ubuntu-latest
89101
steps:
90-
- uses: actions/checkout@v4
91-
- uses: actions/download-artifact@v3
92-
- name: Display structure of downloaded files
102+
- name: Checkout Crate
103+
uses: actions/checkout@v4
104+
105+
- name: Download All Artifacts
106+
uses: actions/download-artifact@v4
107+
108+
- name: Display Structure of Downloaded Files
93109
run: ls -R
94-
- run: find executed_* -type f -exec cat {} + | sort > executed
95-
- run: source ./fuzz/fuzz-util.sh && listTargetNames | sort | diff - executed
110+
111+
- name: Write File With All Executed Targets
112+
run: find executed_* -type f -exec cat {} + | sort > executed
113+
114+
- name: Compare Executed Targets With Available Targets
115+
run: source ./fuzz/fuzz-util.sh && listTargetNames | sort | diff - executed
96116
EOF

src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ pub use crate::merkle::{
5959
cmr::Cmr,
6060
imr::{FirstPassImr, Imr},
6161
tmr::Tmr,
62-
FailEntropy,
62+
FailEntropy, HasCmr,
6363
};
64-
pub use crate::node::{CommitNode, ConstructNode, RedeemNode, WitnessNode};
64+
pub use crate::node::{CommitNode, ConstructNode, Hiding, RedeemNode, WitnessNode};
6565
pub use crate::value::{Value, Word};
6666
pub use simplicity_sys as ffi;
6767
use std::fmt;
@@ -78,8 +78,6 @@ pub fn leaf_version() -> elements::taproot::LeafVersion {
7878
pub enum Error {
7979
/// Decoder error
8080
Decode(decode::Error),
81-
/// A disconnect node was populated at commitment time
82-
DisconnectCommitTime,
8381
/// A disconnect node was *not* populated at redeem time
8482
DisconnectRedeemTime,
8583
/// Type-checking error
@@ -99,9 +97,6 @@ impl fmt::Display for Error {
9997
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10098
match self {
10199
Error::Decode(ref e) => fmt::Display::fmt(e, f),
102-
Error::DisconnectCommitTime => {
103-
f.write_str("disconnect node had two children (commit time); must have one")
104-
}
105100
Error::DisconnectRedeemTime => {
106101
f.write_str("disconnect node had one child (redeem time); must have two")
107102
}
@@ -119,7 +114,6 @@ impl std::error::Error for Error {
119114
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
120115
match *self {
121116
Error::Decode(ref e) => Some(e),
122-
Error::DisconnectCommitTime => None,
123117
Error::DisconnectRedeemTime => None,
124118
Error::Type(ref e) => Some(e),
125119
Error::Execution(ref e) => Some(e),

src/merkle/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ use crate::Value;
1515
use hashes::{sha256, Hash, HashEngine};
1616
use std::fmt;
1717

18+
/// Trait for types that have a Commitment Merkle Root.
19+
pub trait HasCmr {
20+
/// Access the Commitment Merkle Root.
21+
fn cmr(&self) -> cmr::Cmr;
22+
}
23+
1824
/// 512-bit opaque blob of data used to seed `Fail` nodes
1925
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
2026
pub struct FailEntropy([u8; 64]);

src/node/construct.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,10 @@ impl<J: Jet> ConstructNode<J> {
9898
fn convert_disconnect(
9999
&mut self,
100100
_: &PostOrderIterItem<&ConstructNode<J>>,
101-
maybe_converted: Option<&Arc<CommitNode<J>>>,
101+
_: Option<&Arc<CommitNode<J>>>,
102102
_: &Option<Arc<ConstructNode<J>>>,
103103
) -> Result<NoDisconnect, Self::Error> {
104-
if maybe_converted.is_some() {
105-
Err(crate::Error::DisconnectCommitTime)
106-
} else {
107-
Ok(NoDisconnect)
108-
}
104+
Ok(NoDisconnect)
109105
}
110106

111107
fn convert_data(

0 commit comments

Comments
 (0)