Skip to content

Commit 897e3f8

Browse files
committed
Merge #231: Add CMR to compiler JSON output
5c63de2 Add CMR to compiler output (0ceanslim) Pull request description: The compiler currently outputs only the program binary (base64). Callers deploying programs on-chain also need the Commitment Merkle Root (CMR) to: - Derive the taproot address (P2TR scriptPubKey) - Build the control block for script-path spending Without CMR in the output, callers must reimplement the entire commitment hash computation externally. Since the CMR is already computed internally during compilation, this patch exposes it by adding a cmr field (hex string) to both the Output struct and the JSON output (--json flag). The human-readable display also prints it. The change is non-breaking — existing callers that ignore unknown JSON fields are unaffected. ACKs for top commit: apoelstra: ACK 5c63de2; successfully ran local tests Tree-SHA512: f04ae3a9baeafc4b37941dc5979ab2d73456009158a933789c893331a8f7f724d7153381488f378372ae9012046da07fdafa0be85abb7ea6f758746fef8c19a5
2 parents baff7fa + 5c63de2 commit 897e3f8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ struct Output {
1414
witness: Option<String>,
1515
/// Simplicity program ABI metadata to the program which the user provides.
1616
abi_meta: Option<AbiMeta>,
17+
/// Commitment Merkle Root (CMR) of the program, hex encoded.
18+
cmr: String,
1719
}
1820

1921
impl fmt::Display for Output {
2022
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2123
writeln!(f, "Program:\n{}", self.program)?;
24+
writeln!(f, "CMR:\n{}", self.cmr)?;
2225
if let Some(witness) = &self.witness {
2326
writeln!(f, "Witness:\n{}", witness)?;
2427
}
@@ -156,10 +159,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
156159
None
157160
};
158161

162+
let cmr_hex = compiled.commit().cmr().to_string();
159163
let output = Output {
160164
program: Base64Display::new(&program_bytes, &STANDARD).to_string(),
161165
witness: witness_bytes.map(|bytes| Base64Display::new(&bytes, &STANDARD).to_string()),
162166
abi_meta: abi_opt,
167+
cmr: cmr_hex,
163168
};
164169

165170
if output_json {

0 commit comments

Comments
 (0)