-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix synthesis of circuits with Scalar outputs
#3258
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: staging
Are you sure you want to change the base?
Changes from 2 commits
87ca4db
eb110e5
97f8607
ce63c48
be31840
030e388
c4ecfcd
a1f4006
ea34051
f909e5f
2e5fa67
db298eb
a409e24
20af680
a176d93
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 |
|---|---|---|
|
|
@@ -184,7 +184,8 @@ impl<N: Network> Stack<N> { | |
| outputs | ||
| } | ||
|
|
||
| /// Executes a program function on the given inputs. | ||
| /// Executes a program function on the given inputs. The output includes a `Response` object if | ||
| /// not in `CheckDeployment` or `Synthesize` mode. | ||
| /// | ||
| /// Note: To execute a transition, do **not** call this method. Instead, call `Process::execute`. | ||
| /// | ||
|
|
@@ -196,7 +197,7 @@ impl<N: Network> Stack<N> { | |
| console_caller: Option<ProgramID<N>>, | ||
| console_root_tvk: Option<Field<N>>, | ||
| rng: &mut R, | ||
| ) -> Result<Response<N>, StackExecError> { | ||
| ) -> Result<Option<Response<N>>, StackExecError> { | ||
| let timer = timer!("Stack::execute_function"); | ||
|
|
||
| // Ensure the global constants for the Aleo environment are initialized. | ||
|
|
@@ -541,17 +542,26 @@ impl<N: Network> Stack<N> { | |
| Self::log_circuit::<A>("Complete", &call_stack_type); | ||
|
|
||
| // Eject the response. | ||
| let response = response.eject_value(); | ||
| let console_response = | ||
| if matches!(registers.call_stack_ref(), CallStack::Synthesize(..) | CallStack::CheckDeployment(..)) { | ||
| // When synthesizing proving/verifying keys or checking the latter, | ||
| // the values in the Response object are not relevant, and neither is its console counterpart. | ||
| None | ||
| } else { | ||
| let console_response = response.eject_value(); | ||
|
|
||
| if console_response.outputs().len() != output_types.len() { | ||
| return Err(anyhow!("Number of outputs does not match number of output types").into()); | ||
| } | ||
|
|
||
| if response.outputs().len() != output_types.len() { | ||
| return Err(anyhow!("Number of outputs does not match number of output types").into()); | ||
| } | ||
| // Ensure the outputs matches the expected value types. | ||
| console_response.outputs().iter().zip_eq(&output_types).try_for_each(|(output, output_type)| { | ||
| // Ensure the output matches its expected type. | ||
| self.matches_value_type(output, output_type) | ||
| })?; | ||
|
|
||
| // Ensure the outputs matches the expected value types. | ||
| response.outputs().iter().zip_eq(&output_types).try_for_each(|(output, output_type)| { | ||
| // Ensure the output matches its expected type. | ||
| self.matches_value_type(output, output_type) | ||
| })?; | ||
| Some(console_response) | ||
| }; | ||
|
|
||
| // If the circuit is in `Execute` or `PackageRun` mode, then ensure the circuit is satisfied. | ||
| if matches!(registers.call_stack_ref(), CallStack::Execute(..) | CallStack::PackageRun(..)) { | ||
|
|
@@ -582,7 +592,12 @@ impl<N: Network> Stack<N> { | |
| // If the circuit is in `Authorize` mode, then save the transition. | ||
| if let CallStack::Authorize(_, _, authorization) = registers.call_stack_ref() { | ||
| // Construct the transition. | ||
| let transition = Transition::from(&console_request, &response, &output_types, &output_registers)?; | ||
| let transition = Transition::from( | ||
| &console_request, | ||
| console_response.as_ref().unwrap(), | ||
|
Collaborator
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. Maybe justify why this unwrap is safe (an expect maybe) |
||
| &output_types, | ||
| &output_registers, | ||
| )?; | ||
|
|
||
| // Add the transition to the authorization. | ||
| authorization.insert_transition(transition)?; | ||
|
|
@@ -608,7 +623,12 @@ impl<N: Network> Stack<N> { | |
| registers.ensure_console_and_circuit_registers_match()?; | ||
|
|
||
| // Construct the transition. | ||
| let transition = Transition::from(&console_request, &response, &output_types, &output_registers)?; | ||
| let transition = Transition::from( | ||
| &console_request, | ||
| console_response.as_ref().unwrap(), | ||
|
Collaborator
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. Same here. |
||
| &output_types, | ||
| &output_registers, | ||
| )?; | ||
|
|
||
| // Retrieve the proving key. | ||
| let proving_key = self.get_proving_key(function.name())?; | ||
|
|
@@ -655,7 +675,7 @@ impl<N: Network> Stack<N> { | |
| finish!(timer); | ||
|
|
||
| // Return the response. | ||
| Ok(response) | ||
| Ok(console_response) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ mod registers_trait; | |
| use crate::{CallStack, RegisterTypes}; | ||
| use console::{ | ||
| network::prelude::*, | ||
| program::{Entry, Literal, Plaintext, Register, Request, Value}, | ||
| program::{Entry, Literal, Plaintext, PlaintextType, Register, RegisterType, Request, Value}, | ||
|
Contributor
Author
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. They are used in the child module |
||
| types::{Address, Field}, | ||
| }; | ||
| use snarkvm_synthesizer_program::{Operand, RegistersCircuit, RegistersSigner, RegistersTrait, StackTrait}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.