pub struct Stack<N: Network> { /* private fields */ }Implementations§
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Authorizes a call to the program function for the given inputs.
Authorizes a call to the program function for the given inputs.
Compared to authorize, this method does not check for circuit satisfiability of the request.
Produces a mocked Authorization for a call to the given function on
the supplied inputs using the provided caller address. The resulting
Authorization has the same size as the one which would be produced
(and signed) using the private key corresponding to that address and can
therefore be used to compute the cost of the associated Execution, but
many of its values (such as the input IDs in the Requests) may not be
correct. This method does not check circuit satisfiability or Request
validity.
Authorizes a call to a public function for the given request.
Compared to authorize, no private key is needed, but this only works for single public requests.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn deploy<A: Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
rng: &mut R,
) -> Result<Deployment<N>>
pub fn deploy<A: Aleo<Network = N>, R: Rng + CryptoRng>( &self, rng: &mut R, ) -> Result<Deployment<N>>
Deploys the given program ID, if it does not exist.
Sourcepub fn verify_deployment<A: Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
_consensus_version: ConsensusVersion,
deployment: &Deployment<N>,
rng: &mut R,
) -> Result<()>
pub fn verify_deployment<A: Aleo<Network = N>, R: Rng + CryptoRng>( &self, _consensus_version: ConsensusVersion, deployment: &Deployment<N>, rng: &mut R, ) -> Result<()>
Checks each function in the program on the given verifying key and certificate.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn evaluate_closure<A: Aleo<Network = N>>(
&self,
closure: &Closure<N>,
inputs: &[Value<N>],
call_stack: CallStack<N>,
signer: Address<N>,
caller: Address<N>,
tvk: Field<N>,
) -> Result<Vec<Value<N>>, StackEvalError>
pub fn evaluate_closure<A: Aleo<Network = N>>( &self, closure: &Closure<N>, inputs: &[Value<N>], call_stack: CallStack<N>, signer: Address<N>, caller: Address<N>, tvk: Field<N>, ) -> Result<Vec<Value<N>>, StackEvalError>
Evaluates a program closure on the given inputs.
§Errors
This method will halt if the given inputs are not the same length as the input statements.
Sourcepub fn evaluate_function<A: Aleo<Network = N>, R: CryptoRng + Rng>(
&self,
call_stack: CallStack<N>,
caller: Option<ProgramID<N>>,
root_tvk: Option<Field<N>>,
rng: &mut R,
) -> Result<Response<N>, StackEvalError>
pub fn evaluate_function<A: Aleo<Network = N>, R: CryptoRng + Rng>( &self, call_stack: CallStack<N>, caller: Option<ProgramID<N>>, root_tvk: Option<Field<N>>, rng: &mut R, ) -> Result<Response<N>, StackEvalError>
Evaluates a program function on the given inputs.
§Errors
This method will halt if the given inputs are not the same length as the input statements.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn execute_closure<A: Aleo<Network = N>>(
&self,
closure: &Closure<N>,
inputs: &[Value<A>],
call_stack: CallStack<N>,
signer: Address<A>,
caller: Address<A>,
tvk: Field<A>,
) -> Result<Vec<Value<A>>, StackExecError>
pub fn execute_closure<A: Aleo<Network = N>>( &self, closure: &Closure<N>, inputs: &[Value<A>], call_stack: CallStack<N>, signer: Address<A>, caller: Address<A>, tvk: Field<A>, ) -> Result<Vec<Value<A>>, StackExecError>
Executes a program closure on the given inputs.
§Errors
This method will halt if the given inputs are not the same length as the input statements.
Sourcepub fn execute_function<A: Aleo<Network = N>, R: CryptoRng + Rng>(
&self,
call_stack: CallStack<N>,
console_caller: Option<ProgramID<N>>,
console_root_tvk: Option<Field<N>>,
rng: &mut R,
) -> Result<Response<N>, StackExecError>
pub fn execute_function<A: Aleo<Network = N>, R: CryptoRng + Rng>( &self, call_stack: CallStack<N>, console_caller: Option<ProgramID<N>>, console_root_tvk: Option<Field<N>>, rng: &mut R, ) -> Result<Response<N>, StackExecError>
Executes a program function on the given inputs.
Note: To execute a transition, do not call this method. Instead, call Process::execute.
§Errors
This method will halt if the given inputs are not the same length as the input statements.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn check_upgrade_is_valid(
old_program: &Program<N>,
new_program: &Program<N>,
) -> Result<()>
pub fn check_upgrade_is_valid( old_program: &Program<N>, new_program: &Program<N>, ) -> Result<()>
Checks that the new program is a valid upgrade. At a high-level, an upgrade must preserve the existing interfaces of the original program. An upgrade may add new components, except for constructors, and modify logic only in functions and finalize scopes. An upgrade may also be exactly the same as the original program.
The order of the components in the new program may be modified, as long as the interfaces remain the same.
An detailed overview of what an upgrade can and cannot do is given below:
| Program Component | Delete | Modify | Add |
|---|---|---|---|
| import | ❌ | ❌ | ✅ |
| constructor | ❌ | ❌ | ❌ |
| mapping | ❌ | ❌ | ✅ |
| struct | ❌ | ❌ | ✅ |
| record | ❌ | ❌ | ✅ |
| closure | ❌ | ❌ | ✅ |
| function | ❌ | ✅ (logic) | ✅ |
| finalize | ❌ | ✅ (logic) | ✅ |
| view | ❌ | ✅ (logic) | ✅ |
| —————–– | –––– | ––––––– | —–– |
There is one important caveat in that output register indices MUST remain the same.
For example, changing output r10 as <NAME>.record into output r11 as <NAME>.record would not be a valid upgrade.
This restriction is necessary because the output register index is instantiated as a constant in the caller circuit.
This check is enforced in check_transaction in synthesizer/src/vm/verify.rs.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn sample_plaintext<R: Rng + CryptoRng>(
&self,
plaintext_type: &PlaintextType<N>,
rng: &mut R,
) -> Result<Plaintext<N>>
pub fn sample_plaintext<R: Rng + CryptoRng>( &self, plaintext_type: &PlaintextType<N>, rng: &mut R, ) -> Result<Plaintext<N>>
Samples a plaintext value according to the given plaintext type.
Sourcepub fn sample_future<R: Rng + CryptoRng>(
&self,
locator: &Locator<N>,
rng: &mut R,
) -> Result<Future<N>>
pub fn sample_future<R: Rng + CryptoRng>( &self, locator: &Locator<N>, rng: &mut R, ) -> Result<Future<N>>
Samples a future value according to the given future type.
Sourcepub fn sample_dynamic_future<R: Rng + CryptoRng>(
&self,
rng: &mut R,
) -> Result<DynamicFuture<N>>
pub fn sample_dynamic_future<R: Rng + CryptoRng>( &self, rng: &mut R, ) -> Result<DynamicFuture<N>>
Samples a dynamic future value.
Sourcepub fn sample_dynamic_record<R: Rng + CryptoRng>(
&self,
rng: &mut R,
) -> Result<DynamicRecord<N>>
pub fn sample_dynamic_record<R: Rng + CryptoRng>( &self, rng: &mut R, ) -> Result<DynamicRecord<N>>
Samples a dynamic record value.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn synthesize_key<A: Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
function_name: &Identifier<N>,
rng: &mut R,
) -> Result<()>
pub fn synthesize_key<A: Aleo<Network = N>, R: Rng + CryptoRng>( &self, function_name: &Identifier<N>, rng: &mut R, ) -> Result<()>
Synthesizes the proving key and verifying key for the given function name.
Sourcepub fn synthesize_from_assignment(
&self,
function_name: &Identifier<N>,
assignment: &Assignment<N::Field>,
) -> Result<()>
pub fn synthesize_from_assignment( &self, function_name: &Identifier<N>, assignment: &Assignment<N::Field>, ) -> Result<()>
Synthesizes and stores the (proving_key, verifying_key) for the given function name and assignment.
Sourcepub fn synthesize_translation_key<A: Aleo<Network = N>, R: Rng + CryptoRng>(
&self,
record_name: &Identifier<N>,
rng: &mut R,
) -> Result<()>
pub fn synthesize_translation_key<A: Aleo<Network = N>, R: Rng + CryptoRng>( &self, record_name: &Identifier<N>, rng: &mut R, ) -> Result<()>
Synthesizes the proving key and verifying key for the translation circuit of the record with the given name.
Source§impl<N: Network> Stack<N>
impl<N: Network> Stack<N>
Sourcepub fn new(process: &Process<N>, program: &Program<N>) -> Result<Self>
pub fn new(process: &Process<N>, program: &Program<N>) -> Result<Self>
Initializes a new stack given the process and the program.
Sourcepub fn new_raw(
process: &Process<N>,
program: &Program<N>,
edition: u16,
) -> Result<Self>
pub fn new_raw( process: &Process<N>, program: &Program<N>, edition: u16, ) -> Result<Self>
Partially initializes a new stack, given the process and the program, without checking for validity.
Unlike Stack::new, this method accepts an explicit edition and skips upgrade validation,
which is necessary for amendments that preserve the existing edition rather than incrementing it.
A Stack created by this method must also call initialize_and_check.
Sourcepub fn initialize_and_check(&self, process: &Process<N>) -> Result<()>
pub fn initialize_and_check(&self, process: &Process<N>) -> Result<()>
Initializes and checks the register state and well-formedness of the stack, even if it has already been initialized.
Sourcepub fn get_constructor_types(&self) -> Result<FinalizeTypes<N>>
pub fn get_constructor_types(&self) -> Result<FinalizeTypes<N>>
Returns the constructor types for the program.
Sourcepub fn get_register_types(
&self,
name: &Identifier<N>,
) -> Result<RegisterTypes<N>>
pub fn get_register_types( &self, name: &Identifier<N>, ) -> Result<RegisterTypes<N>>
Returns the register types for the given closure or function name.
Sourcepub fn get_finalize_types(
&self,
name: &Identifier<N>,
) -> Result<FinalizeTypes<N>>
pub fn get_finalize_types( &self, name: &Identifier<N>, ) -> Result<FinalizeTypes<N>>
Returns the register types for the given finalize name.
Sourcepub fn get_view_types(&self, name: &Identifier<N>) -> Result<FinalizeTypes<N>>
pub fn get_view_types(&self, name: &Identifier<N>) -> Result<FinalizeTypes<N>>
Returns the register types for the given view function name.
Trait Implementations§
Source§impl<N: Network> StackTrait<N> for Stack<N>
impl<N: Network> StackTrait<N> for Stack<N>
Source§fn matches_value_type(
&self,
value: &Value<N>,
value_type: &ValueType<N>,
) -> Result<()>
fn matches_value_type( &self, value: &Value<N>, value_type: &ValueType<N>, ) -> Result<()>
Checks that the given value matches the layout of the value type.
Source§fn matches_register_type(
&self,
stack_value: &Value<N>,
register_type: &RegisterType<N>,
) -> Result<()>
fn matches_register_type( &self, stack_value: &Value<N>, register_type: &RegisterType<N>, ) -> Result<()>
Checks that the given stack value matches the layout of the register type.
Source§fn matches_external_record(
&self,
record: &Record<N, Plaintext<N>>,
locator: &Locator<N>,
) -> Result<()>
fn matches_external_record( &self, record: &Record<N, Plaintext<N>>, locator: &Locator<N>, ) -> Result<()>
Checks that the given record matches the layout of the external record type.
Source§fn matches_record(
&self,
record: &Record<N, Plaintext<N>>,
record_name: &Identifier<N>,
) -> Result<()>
fn matches_record( &self, record: &Record<N, Plaintext<N>>, record_name: &Identifier<N>, ) -> Result<()>
Checks that the given record matches the layout of the record type.
Source§fn matches_plaintext(
&self,
plaintext: &Plaintext<N>,
plaintext_type: &PlaintextType<N>,
) -> Result<()>
fn matches_plaintext( &self, plaintext: &Plaintext<N>, plaintext_type: &PlaintextType<N>, ) -> Result<()>
Checks that the given plaintext matches the layout of the plaintext type.
Source§fn matches_future(&self, future: &Future<N>, locator: &Locator<N>) -> Result<()>
fn matches_future(&self, future: &Future<N>, locator: &Locator<N>) -> Result<()>
Checks that the given future matches the layout of the future type.
Source§fn contains_proving_key(&self, function_or_record_name: &Identifier<N>) -> bool
fn contains_proving_key(&self, function_or_record_name: &Identifier<N>) -> bool
Returns true if the proving key for the given name exists.
The name can be a function name or a record name (for translation keys).
Source§fn get_proving_key(
&self,
function_or_record_name: &Identifier<N>,
) -> Result<ProvingKey<N>>
fn get_proving_key( &self, function_or_record_name: &Identifier<N>, ) -> Result<ProvingKey<N>>
Returns the proving key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn insert_proving_key(
&self,
function_or_record_name: &Identifier<N>,
proving_key: ProvingKey<N>,
) -> Result<()>
fn insert_proving_key( &self, function_or_record_name: &Identifier<N>, proving_key: ProvingKey<N>, ) -> Result<()>
Inserts the given proving key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn remove_proving_key(&self, function_or_record_name: &Identifier<N>)
fn remove_proving_key(&self, function_or_record_name: &Identifier<N>)
Removes the proving key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn contains_verifying_key(
&self,
function_or_record_name: &Identifier<N>,
) -> bool
fn contains_verifying_key( &self, function_or_record_name: &Identifier<N>, ) -> bool
Returns true if the verifying key for the given name exists.
The name can be a function name or a record name (for translation keys).
Source§fn get_verifying_key(
&self,
function_or_record_name: &Identifier<N>,
) -> Result<VerifyingKey<N>>
fn get_verifying_key( &self, function_or_record_name: &Identifier<N>, ) -> Result<VerifyingKey<N>>
Returns the verifying key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn insert_verifying_key(
&self,
function_or_record_name: &Identifier<N>,
verifying_key: VerifyingKey<N>,
) -> Result<()>
fn insert_verifying_key( &self, function_or_record_name: &Identifier<N>, verifying_key: VerifyingKey<N>, ) -> Result<()>
Inserts the given verifying key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn remove_verifying_key(&self, function_or_record_name: &Identifier<N>)
fn remove_verifying_key(&self, function_or_record_name: &Identifier<N>)
Removes the verifying key for the given name. The name can be a function name or a record name (for translation keys).
Source§fn program_id(&self) -> &ProgramID<N>
fn program_id(&self) -> &ProgramID<N>
Returns the program ID.
Source§fn program_address(&self) -> &Address<N>
fn program_address(&self) -> &Address<N>
Returns the program address.
Source§fn program_checksum(&self) -> &[U8<N>; 32]
fn program_checksum(&self) -> &[U8<N>; 32]
Returns the program checksum.
Source§fn program_checksum_as_field(&self) -> Result<Field<N>>
fn program_checksum_as_field(&self) -> Result<Field<N>>
Returns the program checksum as a field element.
Source§fn program_edition(&self) -> U16<N>
fn program_edition(&self) -> U16<N>
Returns the program edition.
Source§fn program_amendment_count(&self) -> u64
fn program_amendment_count(&self) -> u64
Returns the number of amendments for the current program edition.
Source§fn set_program_amendment_count(&mut self, program_amendment_count: u64)
fn set_program_amendment_count(&mut self, program_amendment_count: u64)
Sets the number of amendments for the current program edition.
Source§fn program_owner(&self) -> &Option<Address<N>>
fn program_owner(&self) -> &Option<Address<N>>
Returns the program owner.
Source§fn set_program_owner(&mut self, program_owner: Option<Address<N>>)
fn set_program_owner(&mut self, program_owner: Option<Address<N>>)
Sets the program owner.
The program owner should only be set for programs that are deployed after ConsensusVersion::V9 is active.
Source§fn get_external_stack(&self, program_id: &ProgramID<N>) -> Result<Arc<Stack<N>>>
fn get_external_stack(&self, program_id: &ProgramID<N>) -> Result<Arc<Stack<N>>>
Returns the external stack for the given program ID.
Attention - this function is used to check the existence of the external program. Developers should explicitly handle the error case so as to not default to the main program.
Source§fn get_stack_global(&self, program_id: &ProgramID<N>) -> Result<Arc<Stack<N>>>
fn get_stack_global(&self, program_id: &ProgramID<N>) -> Result<Arc<Stack<N>>>
Returns the stack for the given program ID.
Attention - this function does NOT check that the program is imported by the current program. This function is only to be used for resolution during dynamic dispatch.
Source§fn get_function(&self, function_name: &Identifier<N>) -> Result<Function<N>>
fn get_function(&self, function_name: &Identifier<N>) -> Result<Function<N>>
Returns the function with the given function name.
Source§fn get_function_ref(
&self,
function_name: &Identifier<N>,
) -> Result<&Function<N>>
fn get_function_ref( &self, function_name: &Identifier<N>, ) -> Result<&Function<N>>
Returns a reference to the function with the given function name.
Source§fn get_minimum_number_of_calls(
&self,
function_name: &Identifier<N>,
) -> Result<usize>
fn get_minimum_number_of_calls( &self, function_name: &Identifier<N>, ) -> Result<usize>
Returns the minimum number of calls for the given function name. In the case where there are no dynamic calls, this is equivalent to the total number of calls.
Source§fn contains_dynamic_call(&self, function_name: &Identifier<N>) -> Result<bool>
fn contains_dynamic_call(&self, function_name: &Identifier<N>) -> Result<bool>
Returns whether or not a function has a dynamic call in its execution.
Source§fn sample_value<R: Rng + CryptoRng>(
&self,
burner_address: &Address<N>,
register_type: &RegisterType<N>,
rng: &mut R,
) -> Result<Value<N>>
fn sample_value<R: Rng + CryptoRng>( &self, burner_address: &Address<N>, register_type: &RegisterType<N>, rng: &mut R, ) -> Result<Value<N>>
Returns a value for the given register type.
Source§fn sample_record<R: Rng + CryptoRng>(
&self,
burner_address: &Address<N>,
record_name: &Identifier<N>,
nonce: Group<N>,
rng: &mut R,
) -> Result<Record<N, Plaintext<N>>>
fn sample_record<R: Rng + CryptoRng>( &self, burner_address: &Address<N>, record_name: &Identifier<N>, nonce: Group<N>, rng: &mut R, ) -> Result<Record<N, Plaintext<N>>>
Returns a record for the given record name, with the given burner address and nonce.
Source§fn sample_record_using_tvk<R: Rng + CryptoRng>(
&self,
burner_address: &Address<N>,
record_name: &Identifier<N>,
tvk: Field<N>,
index: Field<N>,
rng: &mut R,
) -> Result<Record<N, Plaintext<N>>>
fn sample_record_using_tvk<R: Rng + CryptoRng>( &self, burner_address: &Address<N>, record_name: &Identifier<N>, tvk: Field<N>, index: Field<N>, rng: &mut R, ) -> Result<Record<N, Plaintext<N>>>
Returns a record for the given record name, deriving the nonce from tvk and index.
Source§fn evaluate_view(
&self,
state: FinalizeGlobalState,
store: &dyn FinalizeStoreTrait<N>,
view_name: &Identifier<N>,
inputs: Vec<Value<N>>,
) -> Result<Vec<Value<N>>>
fn evaluate_view( &self, state: FinalizeGlobalState, store: &dyn FinalizeStoreTrait<N>, view_name: &Identifier<N>, inputs: Vec<Value<N>>, ) -> Result<Vec<Value<N>>>
impl<N: Network> Eq for Stack<N>
Auto Trait Implementations§
impl<N> Freeze for Stack<N>
impl<N> !RefUnwindSafe for Stack<N>
impl<N> Send for Stack<N>
impl<N> Sync for Stack<N>
impl<N> Unpin for Stack<N>where
<N as Environment>::Projective: Unpin,
N: Unpin,
<N as Environment>::Field: Unpin,
<N as Environment>::Scalar: Unpin,
impl<N> UnsafeUnpin for Stack<N>
impl<N> !UnwindSafe for Stack<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more