Skip to content

Commit

Permalink
Merge #91: Witness update
Browse files Browse the repository at this point in the history
70535b6 test: Parse witness maps (Christian Lewe)
eeddadd feat: Default witness map (Christian Lewe)
ef2db67 feat: Generate arbitrary witness maps (Christian Lewe)
5d7a91a feat: Serialize witness map (Christian Lewe)
160b97f feat: Get length of witness map (Christian Lewe)
d23acfa doc: the -> a (Christian Lewe)
b5b0904 doc: Fix typos (Christian Lewe)

Pull request description:

  Add some methods to make the map of witness values more useful. Test witness serialization in a fuzz test. Fix some docs.

ACKs for top commit:
  apoelstra:
    ACK 70535b6 successfully ran local tests

Tree-SHA512: f843e0708768eb0a1b65d93ced10c74db686f55fccd978f01789bff8a9eb3a6c930498f96f8587c6423965f2f9efec5db528a338d80d4f0d5371d93fbe681715
  • Loading branch information
uncomputable committed Oct 2, 2024
2 parents 40a9c32 + 70535b6 commit f15dcc4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 43 deletions.
82 changes: 41 additions & 41 deletions codegen/src/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ pub fn documentation(jet: Elements) -> &'static str {
Elements::Eq32 => "Check if two 32-bit values are equal.",
Elements::Eq64 => "Check if two 64-bit values are equal.",
Elements::Eq256 => "Check if two 256-bit values are equal.",
Elements::FullLeftShift8_1 => "Helper for left-shifting bits. The bits are shifted from the 1-bit value into the 8-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift8_2 => "Helper for left-shifting bits. The bits are shifted from the 2-bit value into the 8-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift8_4 => "Helper for left-shifting bits. The bits are shifted from the 4-bit value into the 8-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift16_1 => "Helper for left-shifting bits. The bits are shifted from the 1-bit value into the 16-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift16_2 => "Helper for left-shifting bits. The bits are shifted from the 2-bit value into the 16-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift16_4 => "Helper for left-shifting bits. The bits are shifted from the 4-bit value into the 16-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift16_8 => "Helper for left-shifting bits. The bits are shifted from the 8-bit value into the 16-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift32_1 => "Helper for left-shifting bits. The bits are shifted from the 1-bit value into the 32-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift32_2 => "Helper for left-shifting bits. The bits are shifted from the 2-bit value into the 32-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift32_4 => "Helper for left-shifting bits. The bits are shifted from the 4-bit value into the 32-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift32_8 => "Helper for left-shifting bits. The bits are shifted from the 8-bit value into the 32-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift32_16 => "Helper for left-shifting bits. The bits are shifted from the 16-bit value into the 32-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullLeftShift64_1 => "Helper for left-shifting bits. The bits are shifted from the 1-bit value into the 64-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift64_2 => "Helper for left-shifting bits. The bits are shifted from the 2-bit value into the 64-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift64_4 => "Helper for left-shifting bits. The bits are shifted from the 4-bit value into the 64-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift64_8 => "Helper for left-shifting bits. The bits are shifted from the 8-bit value into the 64-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift64_16 => "Helper for left-shifting bits. The bits are shifted from the 16-bit value into the 64-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullLeftShift64_32 => "Helper for left-shifting bits. The bits are shifted from the 32-bit value into the 64-bit value. Return the shifted value and the 32 bits that were shifted out.",
Elements::FullRightShift8_1 => "Helper for right-shifting bits. The bits are shifted from the 1-bit value into the 8-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift8_2 => "Helper for right-shifting bits. The bits are shifted from the 2-bit value into the 8-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift8_4 => "Helper for right-shifting bits. The bits are shifted from the 4-bit value into the 8-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift16_1 => "Helper for right-shifting bits. The bits are shifted from the 1-bit value into the 16-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift16_2 => "Helper for right-shifting bits. The bits are shifted from the 2-bit value into the 16-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift16_4 => "Helper for right-shifting bits. The bits are shifted from the 4-bit value into the 16-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift16_8 => "Helper for right-shifting bits. The bits are shifted from the 8-bit value into the 16-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift32_1 => "Helper for right-shifting bits. The bits are shifted from the 1-bit value into the 32-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift32_2 => "Helper for right-shifting bits. The bits are shifted from the 2-bit value into the 32-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift32_4 => "Helper for right-shifting bits. The bits are shifted from the 4-bit value into the 32-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift32_8 => "Helper for right-shifting bits. The bits are shifted from the 8-bit value into the 32-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift32_16 => "Helper for right-shifting bits. The bits are shifted from the 16-bit value into the 32-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullRightShift64_1 => "Helper for right-shifting bits. The bits are shifted from the 1-bit value into the 64-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift64_2 => "Helper for right-shifting bits. The bits are shifted from the 2-bit value into the 64-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift64_4 => "Helper for right-shifting bits. The bits are shifted from the 4-bit value into the 64-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift64_8 => "Helper for right-shifting bits. The bits are shifted from the 8-bit value into the 64-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift64_16 => "Helper for right-shifting bits. The bits are shifted from the 16-bit value into the 64-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullRightShift64_32 => "Helper for right-shifting bits. The bits are shifted from the 32-bit value into the 64-bit value. Return the shifted value and the 32 bits that were shifted out.",
Elements::FullLeftShift8_1 => "Helper for left-shifting bits. The bits are shifted from a 1-bit value into a 8-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift8_2 => "Helper for left-shifting bits. The bits are shifted from a 2-bit value into a 8-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift8_4 => "Helper for left-shifting bits. The bits are shifted from a 4-bit value into a 8-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift16_1 => "Helper for left-shifting bits. The bits are shifted from a 1-bit value into a 16-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift16_2 => "Helper for left-shifting bits. The bits are shifted from a 2-bit value into a 16-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift16_4 => "Helper for left-shifting bits. The bits are shifted from a 4-bit value into a 16-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift16_8 => "Helper for left-shifting bits. The bits are shifted from a 8-bit value into a 16-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift32_1 => "Helper for left-shifting bits. The bits are shifted from a 1-bit value into a 32-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift32_2 => "Helper for left-shifting bits. The bits are shifted from a 2-bit value into a 32-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift32_4 => "Helper for left-shifting bits. The bits are shifted from a 4-bit value into a 32-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift32_8 => "Helper for left-shifting bits. The bits are shifted from a 8-bit value into a 32-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift32_16 => "Helper for left-shifting bits. The bits are shifted from a 16-bit value into a 32-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullLeftShift64_1 => "Helper for left-shifting bits. The bits are shifted from a 1-bit value into a 64-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullLeftShift64_2 => "Helper for left-shifting bits. The bits are shifted from a 2-bit value into a 64-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullLeftShift64_4 => "Helper for left-shifting bits. The bits are shifted from a 4-bit value into a 64-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullLeftShift64_8 => "Helper for left-shifting bits. The bits are shifted from a 8-bit value into a 64-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullLeftShift64_16 => "Helper for left-shifting bits. The bits are shifted from a 16-bit value into a 64-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullLeftShift64_32 => "Helper for left-shifting bits. The bits are shifted from a 32-bit value into a 64-bit value. Return the shifted value and the 32 bits that were shifted out.",
Elements::FullRightShift8_1 => "Helper for right-shifting bits. The bits are shifted from a 1-bit value into a 8-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift8_2 => "Helper for right-shifting bits. The bits are shifted from a 2-bit value into a 8-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift8_4 => "Helper for right-shifting bits. The bits are shifted from a 4-bit value into a 8-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift16_1 => "Helper for right-shifting bits. The bits are shifted from a 1-bit value into a 16-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift16_2 => "Helper for right-shifting bits. The bits are shifted from a 2-bit value into a 16-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift16_4 => "Helper for right-shifting bits. The bits are shifted from a 4-bit value into a 16-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift16_8 => "Helper for right-shifting bits. The bits are shifted from a 8-bit value into a 16-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift32_1 => "Helper for right-shifting bits. The bits are shifted from a 1-bit value into a 32-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift32_2 => "Helper for right-shifting bits. The bits are shifted from a 2-bit value into a 32-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift32_4 => "Helper for right-shifting bits. The bits are shifted from a 4-bit value into a 32-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift32_8 => "Helper for right-shifting bits. The bits are shifted from a 8-bit value into a 32-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift32_16 => "Helper for right-shifting bits. The bits are shifted from a 16-bit value into a 32-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullRightShift64_1 => "Helper for right-shifting bits. The bits are shifted from a 1-bit value into a 64-bit value. Return the shifted value and the 1 bit that was shifted out.",
Elements::FullRightShift64_2 => "Helper for right-shifting bits. The bits are shifted from a 2-bit value into a 64-bit value. Return the shifted value and the 2 bits that were shifted out.",
Elements::FullRightShift64_4 => "Helper for right-shifting bits. The bits are shifted from a 4-bit value into a 64-bit value. Return the shifted value and the 4 bits that were shifted out.",
Elements::FullRightShift64_8 => "Helper for right-shifting bits. The bits are shifted from a 8-bit value into a 64-bit value. Return the shifted value and the 8 bits that were shifted out.",
Elements::FullRightShift64_16 => "Helper for right-shifting bits. The bits are shifted from a 16-bit value into a 64-bit value. Return the shifted value and the 16 bits that were shifted out.",
Elements::FullRightShift64_32 => "Helper for right-shifting bits. The bits are shifted from a 32-bit value into a 64-bit value. Return the shifted value and the 32 bits that were shifted out.",
Elements::High1 => "Return `u1::MAX` = 1.",
Elements::High8 => "Return [`u8::MAX`].",
Elements::High16 => "Return [`u16::MAX`].",
Expand Down Expand Up @@ -372,7 +372,7 @@ Return `(u64::MAX, u64::MAX)` when the preconditions are not satisfied."#,
Elements::GejXEquiv => "Check if the point represents an affine point with the given x-coordinate.",
Elements::GejYIsOdd => "Check if the point represents an affine point with odd y-coordinate.",
Elements::Generate => "Multiply the generator point with the given scalar.",
Elements::LinearCombination1 => "Compute the the linear combination `b * a + c * g` for point `b` and scalars `a` and `c`, where `g` is the generator point.",
Elements::LinearCombination1 => "Compute the linear combination `b * a + c * g` for point `b` and scalars `a` and `c`, where `g` is the generator point.",
Elements::LinearVerify1 => r#"Assert that a point `b` is equal to the linear combination `a.0 * a.1 + a.2 * g`, where `g` is the generator point.
## Panics
Expand All @@ -391,14 +391,14 @@ The assertion fails."#,
Elements::ScalarNormalize => "Return the canonical representation of the scalar.",
Elements::ScalarSquare => "Square a scalar.",
Elements::Scale => "Multiply a point by a scalar.",
Elements::HashToCurve => r#" A cryptographic hash function that results in a point on the secp256k1 curve.
Elements::HashToCurve => r#"A cryptographic hash function that results in a point on the secp256k1 curve.
This matches the hash function used to map asset IDs to asset commitments."#,
Elements::Swu => r#"Algebraically distribute a field element over the secp256k1 curve as defined in
["Indifferentiable Hashing to Barreto-Naehrig Curves" by Pierre-Alain Fouque, Mehdi Tibouchi](https://inria.hal.science/hal-01094321/file/FT12.pdf).
While this by iteslf is not a cryptographic hash function, it can be used as a subrotuine
in a [`hash_to_curve`] function. However the distribution only apporaches uniform when it is called twice."#,
While this by itself is not a cryptographic hash function, it can be used as a subroutine
in a [`hash_to_curve`] function. However, the distribution only approaches uniformity when it is called twice."#,
// Digital Signatures
Elements::Bip0340Verify => r#"Assert that a Schnorr signature matches a public key and message.
Expand Down Expand Up @@ -688,7 +688,7 @@ Use [`tx_lock_distance`] to obtain a relative block height, or [`tx_lock_duratio
Elements::GenesisBlockHash => "Return the SHA256 hash of the genesis block.",
Elements::InputAmount => r#"Return the asset id and the asset amount at the given input index.
Return `None` is the input does not exist."#,
Return `None` if the input does not exist."#,
Elements::InputAnnexHash => r#"Return the SHA256 hash of the annex at the given input:
- Return `Some(Some(x))` if the input has an annex that hashes to `x`.
- Return `Some(None`) if the input has no annex.
Expand Down
8 changes: 8 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ libfuzzer-sys = "0.4"
arbitrary = { version = "1", features = ["derive"] }
simfony = { path = "..", features = ["arbitrary"]}
itertools = "0.13.0"
serde_json = "1.0.105"

[[bin]]
name = "compile_text"
Expand All @@ -34,6 +35,13 @@ test = false
doc = false
bench = false

[[bin]]
name = "parse_witness_rtt"
path = "fuzz_targets/parse_witness_rtt.rs"
test = false
doc = false
bench = false

[[bin]]
name = "reconstruct_value"
path = "fuzz_targets/reconstruct_value.rs"
Expand Down
16 changes: 16 additions & 0 deletions fuzz/fuzz_targets/parse_witness_rtt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

use simfony::witness::WitnessValues;

fuzz_target!(|witness_values: WitnessValues| {
let witness_text =
serde_json::to_string(&witness_values).expect("Witness map should be convertible into JSON");
let parsed_witness_text =
serde_json::from_str(&witness_text).expect("Witness JSON should be parseable");
assert_eq!(
witness_values, parsed_witness_text,
"Witness JSON should parse to original witness map"
);
});
Loading

0 comments on commit f15dcc4

Please sign in to comment.