-
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 3 commits
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,99 @@ | ||
| #!/usr/bin/env php | ||
| <?php | ||
|
|
||
| // This script is useful for finding slow unit tests. | ||
| // | ||
| // The script sorts the output of `cargo test` by duration of | ||
| // each test, and then prints the results in descending order. | ||
| // | ||
| // It also prints stats at the bottom, eg: | ||
| // | ||
| // --- unit test stats --- | ||
| // Count: 733 | ||
| // Total: 974.801 | ||
| // Min: 0.000 | ||
| // Max: 104.073 | ||
| // Mean: 1.3298785811733 | ||
| // Median: 0.118 | ||
| // ---------------------- | ||
| // | ||
| // As of this writing, it is necessary to use the nightly compiler | ||
| // in order to obtain timing for each test. | ||
| // | ||
| // Here is example usage: | ||
| // | ||
| // cargo +nightly test -- -Z unstable-options --report-time 2>&1 | tee tests.out | ||
| // sort_tests.php tests.out | ||
|
|
||
| $file = @$argv[1]; | ||
|
|
||
| if(!$file || !file_exists($file)) { | ||
| die("please provide a file with output of cargo test, eg:\n cargo +nightly test -- -Z unstable-options --report-time 2>&1 | tee tests.out"); | ||
| } | ||
|
|
||
| $lines = file($file); | ||
|
|
||
| $a = []; | ||
| foreach($lines as $line) { | ||
| $fields = explode(' ', $line); | ||
| $key = $fields[count($fields)-1]; | ||
| $key_new = trim(str_replace(['<', '>', 's'], '', $key)); | ||
| if($key_new != $key && is_numeric($key_new) && substr($line, 0, 5) == "test " && !strstr($line, "finished in")) { | ||
| $a[$line] = $key_new; | ||
| } else { | ||
| // echo "skipping $line"; | ||
| } | ||
| } | ||
|
|
||
| arsort($a); | ||
|
|
||
| foreach($a as $line => $time) { | ||
| echo $line ; | ||
| } | ||
|
|
||
| echo "\n\n\n"; | ||
| analyze_float_array(array_values($a)); | ||
|
|
||
|
|
||
|
|
||
| function analyze_float_array(array $numbers): void { | ||
| if (empty($numbers)) { | ||
| echo "Error: The input array is empty. Cannot calculate statistics.\n"; | ||
| return; | ||
| } | ||
|
|
||
| // --- Min and Max --- | ||
| $min = min($numbers); | ||
| $max = max($numbers); | ||
|
|
||
| // --- Mean (Average) --- | ||
| $sum = array_sum($numbers); | ||
| $count = count($numbers); | ||
| $mean = $sum / $count; | ||
|
|
||
| // --- Median --- | ||
| // 1. Sort the array numerically. | ||
| sort($numbers); | ||
|
|
||
| // 2. Determine the middle index(es). | ||
| $middleIndex = floor($count / 2); | ||
|
|
||
| if ($count % 2 === 1) { | ||
| // Odd number of elements: median is the middle element. | ||
| $median = $numbers[$middleIndex]; | ||
| } else { | ||
| // Even number of elements: median is the average of the two middle elements. | ||
| $median = ($numbers[$middleIndex - 1] + $numbers[$middleIndex]) / 2; | ||
| } | ||
|
|
||
| // --- Print Results --- | ||
| echo "--- unit test stats ---\n"; | ||
| echo "Count: " . $count . "\n"; | ||
| echo "Total: " . $sum . "\n"; | ||
| echo "Min: " . $min . "\n"; | ||
| echo "Max: " . $max . "\n"; | ||
| echo "Mean: " . $mean . "\n"; | ||
| echo "Median: " . $median . "\n"; | ||
| echo "----------------------\n"; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,7 @@ pub struct TransactionProofBuilder<'a> { | |
| job_queue: Option<Arc<TritonVmJobQueue>>, | ||
| proof_job_options: Option<TritonVmProofJobOptions>, | ||
| valid_mock: Option<bool>, | ||
| transaction_proof_type: Option<TransactionProofType>, | ||
| } | ||
|
|
||
| impl<'a> TransactionProofBuilder<'a> { | ||
|
|
@@ -161,6 +162,14 @@ impl<'a> TransactionProofBuilder<'a> { | |
| self | ||
| } | ||
|
|
||
| /// specify type of proof to build (optional) | ||
| /// | ||
| /// default = best proof possible based on [VmProvingCapability](crate::api::export::VmProvingCapability) | ||
| pub fn transaction_proof_type(mut self, transaction_proof_type: TransactionProofType) -> Self { | ||
| self.transaction_proof_type = Some(transaction_proof_type); | ||
| self | ||
| } | ||
|
|
||
| /// generate the proof. | ||
| /// | ||
| /// ## Required (one-of) | ||
|
|
@@ -241,16 +250,19 @@ impl<'a> TransactionProofBuilder<'a> { | |
| job_queue, | ||
| proof_job_options, | ||
| valid_mock, | ||
| transaction_proof_type, | ||
| } = self; | ||
|
|
||
| let proof_job_options = proof_job_options.ok_or(ProofRequirement::ProofJobOptions)?; | ||
| let transaction_proof_type = transaction_proof_type | ||
| .unwrap_or_else(|| proof_job_options.job_settings.vm_proving_capability.into()); | ||
|
Comment on lines
+259
to
+260
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This In contrast, |
||
|
|
||
| let valid_mock = valid_mock.unwrap_or(true); | ||
| let job_queue = job_queue.unwrap_or_else(vm_job_queue); | ||
|
|
||
| // note: evaluation order must match order stated in the method doc-comment. | ||
|
|
||
| if proof_job_options.job_settings.proof_type.is_single_proof() { | ||
| if transaction_proof_type.is_single_proof() { | ||
| // claim, nondeterminism --> single proof | ||
| if let Some((c, nd)) = claim_and_nondeterminism { | ||
| return gen_single(c, || nd, job_queue, proof_job_options, valid_mock).await; | ||
|
|
@@ -284,16 +296,37 @@ impl<'a> TransactionProofBuilder<'a> { | |
|
|
||
| // owned primitive witness --> proof_type | ||
| if let Some(w) = primitive_witness { | ||
| return from_witness(Cow::Owned(w), job_queue, proof_job_options, valid_mock).await; | ||
| return from_witness( | ||
| Cow::Owned(w), | ||
| job_queue, | ||
| proof_job_options, | ||
| transaction_proof_type, | ||
| valid_mock, | ||
| ) | ||
| .await; | ||
| } | ||
| // primitive witness reference --> proof_type | ||
| else if let Some(w) = primitive_witness_ref { | ||
| return from_witness(Cow::Borrowed(w), job_queue, proof_job_options, valid_mock).await; | ||
| return from_witness( | ||
| Cow::Borrowed(w), | ||
| job_queue, | ||
| proof_job_options, | ||
| transaction_proof_type, | ||
| valid_mock, | ||
| ) | ||
| .await; | ||
| } | ||
| // transaction_details --> proof_type | ||
| else if let Some(d) = transaction_details { | ||
| let w = d.primitive_witness(); | ||
| return from_witness(Cow::Owned(w), job_queue, proof_job_options, valid_mock).await; | ||
| return from_witness( | ||
| Cow::Owned(w), | ||
| job_queue, | ||
| proof_job_options, | ||
| transaction_proof_type, | ||
| valid_mock, | ||
| ) | ||
| .await; | ||
| } | ||
|
|
||
| Err(ProofRequirement::TransactionProofInput.into()) | ||
|
|
@@ -333,14 +366,12 @@ async fn from_witness( | |
| witness_cow: Cow<'_, PrimitiveWitness>, | ||
| job_queue: Arc<TritonVmJobQueue>, | ||
| proof_job_options: TritonVmProofJobOptions, | ||
| transaction_proof_type: TransactionProofType, | ||
| valid_mock: bool, | ||
| ) -> Result<TransactionProof, CreateProofError> { | ||
| let capability = proof_job_options.job_settings.tx_proving_capability; | ||
| let proof_type = proof_job_options.job_settings.proof_type; | ||
|
|
||
| // generate mock proof, if network uses mock proofs. | ||
| if proof_job_options.job_settings.network.use_mock_proof() { | ||
| let proof = match proof_type { | ||
| let proof = match transaction_proof_type { | ||
| TransactionProofType::PrimitiveWitness => { | ||
| TransactionProof::Witness(witness_cow.into_owned()) | ||
| } | ||
|
|
@@ -356,16 +387,16 @@ async fn from_witness( | |
| return Ok(proof); | ||
| } | ||
|
|
||
| // abort early if machine is too weak | ||
| if !capability.can_prove(proof_type) { | ||
| return Err(CreateProofError::TooWeak { | ||
| proof_type, | ||
| capability, | ||
| }); | ||
| } | ||
| // abort early if machine is too weak. | ||
| // | ||
| // note: the fallible calls below eventually call ProofBuilder::build() | ||
| // which would perform a more expensive verification. Since we know the | ||
| // transaction_proof_type here, we can perform this quick check. | ||
| let capability = proof_job_options.job_settings.vm_proving_capability; | ||
| capability.can_prove(transaction_proof_type)?; | ||
|
|
||
| // produce proof of requested type | ||
| let transaction_proof = match proof_type { | ||
| let transaction_proof = match transaction_proof_type { | ||
| TransactionProofType::PrimitiveWitness => { | ||
| TransactionProof::Witness(witness_cow.into_owned()) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last time I tried to install PHP to run one of the scripts in this repo, I ended up corrupting my operating system and I had to reinstall ubuntu from scratch. (It was certainly not the fault of the script I was trying to run because I had not even gotten to that point.) I am not tempted to try again to see what went wrong the first time.
This is not a vendetta against PHP. I actually think it is a fantastic language and great at what it does. But I do want to raise the question whether it is a good idea to include PHP scripts in this repository. They obviously come with a huge dependency even if the fallout of installing that dependency does not include corrupting the operating system.
Possible alternatives:
If the issue is, "who is going to write the bash/rust/python equivalent?" then I wonder how far we get with asking AI to transcribe it.
If the issue is, "who is going to maintain it?" then PHP is the most ill-suited option for random new developers. (Okay, scratch that. Bash is. But PHP is second. The point remains that rust and python are both more accessible and more popular.)