Skip to content
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

Use evaluate_function for CallStack::PackageRun; Sample response for CallStack::CheckDeployment #2230

Merged
merged 6 commits into from
Jan 9, 2024

Conversation

vicsn
Copy link
Collaborator

@vicsn vicsn commented Dec 4, 2023

Motivation

If we evaluate_function during deployment, we risk hitting false positive failed constraints on our random assignment.

So instead, this PR proposes to sample a response. After sampling, construction of Response is handled the same way evaluate_function.

Test Plan

In the future we will test a wider range of programs.

Related PRs

https://github.com/AleoHQ/snarkVM/pull/2176
https://github.com/AleoHQ/snarkVM/pull/2224
https://github.com/AleoHQ/snarkVM/pull/2226

@vicsn vicsn requested a review from d0cd December 4, 2023 20:17
@vicsn vicsn marked this pull request as ready for review December 5, 2023 09:07
Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Left a few minor comments.

@@ -182,4 +172,46 @@ impl<N: Network> Stack<N> {
// Return the plaintext.
Ok(plaintext)
}

/// Returns a future for the given TODO.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the TODO be swapped out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx 7cba76f!

ExternalRecord(locator) => {
// Retrieve the external stack.
let stack = substack.get_external_stack(locator.program_id())?;
// Sample the input.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Sample the input.
// Sample the output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx 7cba76f!

@@ -83,6 +84,14 @@ pub trait StackProgram<N: Network> {

/// Returns the expected number of calls for the given function name.
fn get_number_of_calls(&self, function_name: &Identifier<N>) -> Result<usize>;

/// Samples a value for the given value_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Samples a value for the given value_type
/// Samples a value for the given value_type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx 7cba76f!

@@ -13,7 +13,7 @@
// limitations under the License.

use super::*;
use console::program::{Argument, FinalizeType};
pub use console::program::{Argument, FinalizeType};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You can move the use here and in sample.rs to the module above. It'll let you get rid of the pub

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx 7cba76f!

@vicsn vicsn force-pushed the sample_response_checkdeployment branch from 7cba76f to 5b68ab6 Compare December 15, 2023 14:55
@vicsn
Copy link
Collaborator Author

vicsn commented Dec 15, 2023

Did another walk through the code, running on a local devnet and deploying and executing max nested programs succeeds.

Signed-off-by: Howard Wu <9260812+howardwu@users.noreply.github.com>
Comment on lines 295 to 300
ExternalRecord(locator) => {
// Retrieve the external stack.
let stack = substack.get_external_stack(locator.program_id())?;
// Sample the output.
stack.sample_value(&address, &Record(*locator.resource()), rng)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move this case directly into the impl of fn sample_value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart a9f3483


// Retrieve the output operands.
let output_operands =
&function.outputs().iter().map(|output| output.operand()).collect::<Vec<_>>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we collecting?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blind code copy pasta 53c69a8

@howardwu howardwu marked this pull request as draft December 27, 2023 05:39
@vicsn vicsn marked this pull request as ready for review December 28, 2023 20:43
@howardwu howardwu merged commit 3d02f7f into testnet3 Jan 9, 2024
77 of 78 checks passed
@howardwu howardwu deleted the sample_response_checkdeployment branch January 9, 2024 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants