Skip to content

Commit

Permalink
Merge #241: simplicity-sys: stop referring to non-exported mkJetCMR f…
Browse files Browse the repository at this point in the history
…unction

78e14de simplicity-sys: stop referring to non-exported mkJetCMR function (Andrew Poelstra)

Pull request description:

  As seen when running

      RUSTFLAGS=-Clink-dead-code cargo test --all-features

  we are referring to a non-exported function mkJetCMR from the C code. By default rustc prunes this function and never tries to link it, but if you add the -Clink-dead-code rustflag (which may be needed when compiling to link with an external fuzzer) then linking fails.

ACKs for top commit:
  uncomputable:
    ACK 78e14de

Tree-SHA512: c473df2bd75afbf5f16090cb91f1834e3076af778b7593e4956824eb245b66eee267cefa0c0a83f76957d4994e002bc4c8c77751a449f0b20d34ef51366020cd
  • Loading branch information
uncomputable committed Aug 3, 2024
2 parents d01ca91 + 78e14de commit e42b267
Showing 1 changed file with 0 additions and 14 deletions.
14 changes: 0 additions & 14 deletions simplicity-sys/src/tests/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ pub mod dag {
pub static c_sizeof_analyses: c_size_t;
pub static c_alignof_analyses: c_size_t;

/// Given the IMR of a jet specification, return the CMR of a jet that implements
/// that specification
pub fn mkJetCMR(imr: *const u32, weight: u64) -> CSha256Midstate;

/// Compute the CMR of a jet of scribe(v) : ONE |- TWO^(2^n) that outputs a given
/// bitstring
pub fn computeWordCMR(value: *const CBitstring, n: c_size_t) -> CSha256Midstate;
Expand Down Expand Up @@ -316,16 +312,6 @@ pub mod dag {
len: c_size_t,
) -> SimplicityErr;
}

/// Convenience wrapper around mkJetCMR that operates on u8 bytes instead of u32
#[allow(non_snake_case)]
pub fn c_mkJetCMR(midstate: hashes::sha256::Midstate, weight: u64) -> hashes::sha256::Midstate {
let mut imr = [0; 32];
for (idx, chunk) in midstate.0.chunks(4).enumerate() {
imr[idx] = u32::from_be_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]);
}
unsafe { mkJetCMR(imr.as_ptr(), weight) }.into()
}
}

pub mod deserialize {
Expand Down

0 comments on commit e42b267

Please sign in to comment.