-
Couldn't load subscription status.
- Fork 32
Correct the proving-capability abstraction for usage with triton-vm Proof (as opposed to TransactionProof) #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
de8dc8a
a254264
52f680c
0717e8a
9fd1e74
20705dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
|
|
||
| use crate::models::blockchain::shared::Hash as NeptuneHash; | ||
| use crate::models::blockchain::transaction::validity::single_proof::SingleProof; | ||
| use crate::models::proof_abstractions::tasm::program::ConsensusProgram; | ||
| use crate::triton_vm::proof::Claim; | ||
| use crate::triton_vm::vm::NonDeterminism; | ||
| use crate::triton_vm::vm::VMState; | ||
|
|
||
| /// enumerates types of proofs that can be logged. | ||
| /// | ||
| /// this type facilitates offering distinct logging modes for: | ||
| /// | ||
| /// 1. `Proof` (any kind of Proof) | ||
| /// 2. `NoWitness` | ||
| /// | ||
| /// The `Proof` mode is useful for logging inputs to every single Proof that is | ||
| /// generated. These include proofs generated from `PrimitiveWitness` meaning | ||
| /// that the claims expose secrets and should not be shared. This mode of | ||
| /// logging is considered a security risk, but can be useful for investigating | ||
| /// or researching alone, or on testnet(s), etc. | ||
| /// | ||
| /// The `NoWitness` mode is useful when logging proof inputs for purposes of | ||
| /// sharing with others, eg neptune-core developers for debugging. However it | ||
| /// does not log any Proofs generated from a `PrimitiveWitness`. | ||
| pub enum LogProofInputsType { | ||
| /// log any inputs of any kind of proof, possibly leaking witness secrets | ||
| Proof, | ||
|
|
||
| /// log inputs of proof, without leaking witness secrets | ||
| NoWitness, | ||
| } | ||
|
|
||
| impl LogProofInputsType { | ||
| /// returns name of logging environment variable | ||
| /// | ||
| /// each variant has an environment variable that specifies the | ||
| /// directory in which to write proof files. | ||
| pub const fn env_var_name(&self) -> &str { | ||
| match *self { | ||
| Self::Proof => "NEPTUNE_VM_STATE_DIR", | ||
| Self::NoWitness => "NEPTUNE_VM_STATE_NO_WITNESS_DIR", | ||
| } | ||
| } | ||
|
|
||
| /// returns file name prefix | ||
| pub const fn file_prefix(&self) -> &str { | ||
| match *self { | ||
| Self::Proof => "vm_state.claim", | ||
| Self::NoWitness => "vm_state.no_witness_claim", | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| /// If the environment variable specified by [LogProofInputsType::env_var_name()] is set, | ||
| /// write the initial VM state to file `<DIR>/<prefix>.<pid>.<claim>.json`. | ||
| /// | ||
| /// where: | ||
| /// DIR = value of environment variable. | ||
| /// prefix = LogProofInputsType::file_prefix() | ||
| /// pid = process-id | ||
| /// claim = hex-encoded hash of input Claim | ||
dan-da marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// | ||
| /// This file can be used to debug the program using the [Triton TUI]: | ||
| /// ```sh | ||
| /// triton-tui --initial-state <file> | ||
| /// ``` | ||
| /// | ||
| /// [Triton TUI]: https://crates.io/crates/triton-tui | ||
| /// | ||
| /// Security: | ||
| /// | ||
| /// Files of type [LogProofInputsType::Proof] should only be used for debugging | ||
| /// by the wallet owner as they may contain wallet secrets. | ||
| /// | ||
| /// Files of type [LogProofInputsType::NoWitness] can be shared with others | ||
| /// eg, neptune-core developers, for purposes of debugging/assistance. | ||
| /// | ||
| /// It is the *callers* responsibility to ensure that the provided claim matches | ||
| /// the `log_proof_inputs_type` | ||
| pub fn maybe_write<'a, F>( | ||
| log_proof_inputs_type: LogProofInputsType, | ||
| claim: &Claim, | ||
| nondeterminism: F, | ||
| ) -> Result<Option<PathBuf>, LogVmStateError> | ||
| where | ||
| F: FnOnce() -> NonDeterminism + Send + Sync + 'a, | ||
| { | ||
| let Ok(dir) = std::env::var(log_proof_inputs_type.env_var_name()) else { | ||
| return Ok(None); | ||
| }; | ||
| let prefix = log_proof_inputs_type.file_prefix(); | ||
|
|
||
| write(&dir, prefix, claim, nondeterminism()).inspect_err(|e| tracing::warn!("{}", e)) | ||
| } | ||
|
|
||
| fn write( | ||
| dir: &str, | ||
| file_prefix: &str, | ||
| claim: &Claim, | ||
| nondeterminism: NonDeterminism, | ||
| ) -> Result<Option<PathBuf>, LogVmStateError> { | ||
| let vm_state = VMState::new( | ||
| SingleProof.program(), | ||
dan-da marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| claim.input.clone().into(), | ||
| nondeterminism, | ||
| ); | ||
|
|
||
| let filename = format!( | ||
| "{}.{}.{}.json", | ||
| file_prefix, | ||
| std::process::id(), | ||
| NeptuneHash::hash(claim).to_hex(), | ||
| ); | ||
|
|
||
| let path = PathBuf::from(dir).join(filename); | ||
|
|
||
| let mut state_file = | ||
| std::fs::File::create(&path).map_err(|e| LogVmStateError::from((path.clone(), e)))?; | ||
| let state = serde_json::to_string(&vm_state)?; | ||
| write!(state_file, "{}", state).map_err(|e| LogVmStateError::from((path.clone(), e)))?; | ||
| Ok(Some(path)) | ||
| } | ||
|
|
||
| #[derive(Debug, thiserror::Error, strum::EnumIs)] | ||
| #[non_exhaustive] | ||
| pub enum LogVmStateError { | ||
| #[error("could not obtain padded-height due to program execution error")] | ||
| IoError { | ||
| path: PathBuf, | ||
| #[source] | ||
| source: std::io::Error, | ||
| }, | ||
|
|
||
| #[error(transparent)] | ||
| SerializeError(#[from] serde_json::Error), | ||
| } | ||
|
|
||
| impl From<(PathBuf, std::io::Error)> for LogVmStateError { | ||
| fn from(v: (PathBuf, std::io::Error)) -> Self { | ||
| let (path, source) = v; | ||
| Self::IoError { path, source } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| pub mod archival_mmr; | ||
| pub(crate) mod log_vm_state; | ||
| pub mod mutator_set; | ||
| pub mod rusty_archival_block_mmr; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.