-
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
Open
Antonio95
wants to merge
15
commits into
staging
Choose a base branch
from
fix/scalar-outputs
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
87ca4db
fixed issue, regenerated expecations
Antonio95 eb110e5
Merge branch 'staging' into fix/scalar-outputs
Antonio95 97f8607
fmt
Antonio95 ce63c48
fixed transaction order in broken check, still hostile (!= 1, 2, 3, 4)
Antonio95 be31840
modified test, moved imports
Antonio95 030e388
unified circuit and console matches_register_type in macro
Antonio95 c4ecfcd
added missing file
Antonio95 a1f4006
Merge branch 'staging' into fix/scalar-outputs
Antonio95 ea34051
fixed fmt after merge
Antonio95 f909e5f
added single quotes, made capitalisation consistent
Antonio95 2e5fa67
Merge branch 'staging' into fix/scalar-outputs
Antonio95 db298eb
removed TODO
Antonio95 a409e24
removed order check in test
Antonio95 20af680
merged staging, resolved conflicts
Antonio95 a176d93
regen expectations
Antonio95 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -188,7 +188,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`. | ||
| /// | ||
|
|
@@ -200,7 +201,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. | ||
|
|
@@ -550,17 +551,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(..)) { | ||
|
|
@@ -591,7 +601,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(), | ||
| &output_types, | ||
| &output_registers, | ||
| )?; | ||
|
|
||
| // Add the transition to the authorization. | ||
| authorization.insert_transition(transition)?; | ||
|
|
@@ -617,7 +632,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())?; | ||
|
|
@@ -664,7 +684,7 @@ impl<N: Network> Stack<N> { | |
| finish!(timer); | ||
|
|
||
| // Return the response. | ||
| Ok(response) | ||
| Ok(console_response) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ mod initialize; | |
| mod sample; | ||
| mod stack_trait; | ||
| mod synthesize; | ||
| mod type_matching; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Maybe justify why this unwrap is safe (an expect maybe)