-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
51 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use super::{Assembler, MidenLib, SatKernel, StdLibrary}; | ||
use miden_core::Kernel; | ||
use miden_objects::transaction::ProvenTransaction; | ||
use miden_verifier::{verify, ProgramInfo, VerificationError}; | ||
|
||
/// The [TransactionVerifier] is used to verify a [ProvenTransaction]. | ||
/// | ||
/// The [TransactionVerifier] contains a [Kernel] object which we use to verify a given | ||
/// transaction against. | ||
pub struct TransactionVerifier { | ||
kernel: Kernel, | ||
} | ||
|
||
impl TransactionVerifier { | ||
// TODO: Do we want to allow the kernel to be passed as an argument to the constructor? | ||
// It probably doesn't make sense to do so now as we only have a single kernel. | ||
/// Creates a new [TransactionVerifier] object. | ||
pub fn new() -> Self { | ||
let kernel = Assembler::default() | ||
.with_library(&MidenLib::default()) | ||
.expect("library is well formed") | ||
.with_library(&StdLibrary::default()) | ||
.expect("library is well formed") | ||
.with_kernel(SatKernel::kernel()) | ||
.expect("kernel is well formed") | ||
.kernel() | ||
.clone(); | ||
Self { kernel } | ||
} | ||
|
||
/// Verifies the provided [ProvenTransaction] against the kernel. | ||
pub fn verify(&self, transaction: ProvenTransaction) -> Result<u32, VerificationError> { | ||
let program_info = ProgramInfo::new(transaction.program_hash(), self.kernel.clone()); | ||
verify( | ||
program_info, | ||
transaction.build_stack_inputs(), | ||
transaction.build_stack_outputs(), | ||
transaction.proof().clone(), | ||
) | ||
} | ||
} |