Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod witness;

use std::sync::Arc;

use simplicity::jet::elements::ElementsEnv;
use simplicity::{jet::Elements, CommitNode, RedeemNode};

pub extern crate either;
Expand Down Expand Up @@ -133,15 +134,31 @@ impl CompiledProgram {
/// - Witness values have a different type than declared in the Simfony program.
/// - There are missing witness values.
pub fn satisfy(&self, witness_values: WitnessValues) -> Result<SatisfiedProgram, String> {
self.satisfy_with_env(witness_values, None)
}

/// Satisfy the Simfony program with the given `witness_values`.
/// If `env` is `None`, the program is not pruned, otherwise it is pruned with the given environment.
///
/// ## Errors
///
/// - Witness values have a different type than declared in the Simfony program.
/// - There are missing witness values.
Comment on lines +143 to +146
Copy link
Collaborator

@uncomputable uncomputable Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

30f125f: nit: pruning fails if the program doesn't run successfully for the given environment and witness data. This is an additional error path, next to the existing two paths.

pub fn satisfy_with_env(
&self,
witness_values: WitnessValues,
env: Option<&ElementsEnv<Arc<elements::Transaction>>>,
) -> Result<SatisfiedProgram, String> {
witness_values
.is_consistent(&self.witness_types)
.map_err(|e| e.to_string())?;
let simplicity_witness = named::to_witness_node(&self.simplicity, witness_values);
let simplicity_redeem = simplicity_witness
.finalize_unpruned()
.map_err(|e| e.to_string())?;
let simplicity_redeem = match env {
Some(env) => simplicity_witness.finalize_pruned(env),
None => simplicity_witness.finalize_unpruned(),
};
Ok(SatisfiedProgram {
simplicity: simplicity_redeem,
simplicity: simplicity_redeem.map_err(|e| e.to_string())?,
debug_symbols: self.debug_symbols.clone(),
})
}
Expand Down