From 8b739c9a4ca0d2f69fab653f18c3e8387c2371a7 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 11 Nov 2024 13:13:48 -0800 Subject: [PATCH 01/13] Add test case and WIP fix --- synthesizer/process/src/finalize.rs | 87 ++++++++++++++----- .../src/stack/finalize_registers/mod.rs | 19 +++- .../src/stack/register_types/initialize.rs | 2 +- .../program/src/logic/command/rand_chacha.rs | 31 +++++-- .../program/src/traits/stack_and_registers.rs | 3 + synthesizer/program/tests/helpers/sample.rs | 1 + .../complex_finalization_2.out | 25 ++++++ .../complex_finalization_2.aleo | 86 ++++++++++++++++++ 8 files changed, 219 insertions(+), 35 deletions(-) create mode 100644 synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out create mode 100644 synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 6606d2d152..6cabeac393 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -104,7 +104,11 @@ impl Process { lap!(timer, "Verify the number of transitions"); // Construct the call graph. - let call_graph = self.construct_call_graph(execution)?; + let call_graph = if state.block_height() > N::CONSENSUS_V2_HEIGHT { + Default::default() + } else { + self.construct_call_graph(execution)? + }; atomic_batch_scope!(store, { // Finalize the root transition. @@ -160,9 +164,11 @@ fn finalize_fee_transition>( fee: &Fee, ) -> Result>> { // Construct the call graph. - let mut call_graph = HashMap::new(); - // Insert the fee transition. - call_graph.insert(*fee.transition_id(), Vec::new()); + let call_graph = if state.block_height() > N::CONSENSUS_V2_HEIGHT { + Default::default() + } else { + HashMap::from([*fee.transition_id(), Vec::new()]) + }; // Finalize the transition. match finalize_transition(state, store, stack, fee, call_graph) { @@ -208,8 +214,11 @@ fn finalize_transition>( // Initialize a stack of active finalize states. let mut states = Vec::new(); + // Initialize a nonce for the finalize registers. + let mut nonce = 0; + // Initialize the top-level finalize state. - states.push(initialize_finalize_state(state, future, stack, *transition.id())?); + states.push(initialize_finalize_state(state, future, stack, *transition.id(), nonce)?); // While there are active finalize states, finalize them. 'outer: while let Some(FinalizeState { @@ -263,26 +272,28 @@ fn finalize_transition>( await_.register() ); - // Get the current transition ID. - let transition_id = registers.transition_id(); - // Get the child transition ID. - let child_transition_id = match call_graph.get(transition_id) { - Some(transitions) => match transitions.get(call_counter) { - Some(transition_id) => *transition_id, - None => bail!("Child transition ID not found."), - }, - None => bail!("Transition ID '{transition_id}' not found in call graph"), - }; + // Get the finalize transition ID. + let finalize_transition_id = + finalize_transition_id(&state, &call_graph, call_counter, *transition.id())?; + + // Increment the nonce. + nonce += 1; // Set up the finalize state for the await. - let callee_state = - match try_vm_runtime!(|| setup_await(state, await_, stack, ®isters, child_transition_id)) { - Ok(Ok(callee_state)) => callee_state, - // If the evaluation fails, bail and return the error. - Ok(Err(error)) => bail!("'finalize' failed to evaluate command ({command}): {error}"), - // If the evaluation fails, bail and return the error. - Err(_) => bail!("'finalize' failed to evaluate command ({command})"), - }; + let callee_state = match try_vm_runtime!(|| setup_await( + state, + await_, + stack, + ®isters, + finalize_transition_id, + nonce + )) { + Ok(Ok(callee_state)) => callee_state, + // If the evaluation fails, bail and return the error. + Ok(Err(error)) => bail!("'finalize' failed to evaluate command ({command}): {error}"), + // If the evaluation fails, bail and return the error. + Err(_) => bail!("'finalize' failed to evaluate command ({command})"), + }; // Increment the call counter. call_counter += 1; @@ -357,6 +368,7 @@ fn initialize_finalize_state<'a, N: Network>( future: &Future, stack: &'a Stack, transition_id: N::TransitionID, + nonce: u64, ) -> Result> { // Get the finalize logic and the stack. let (finalize, stack) = match stack.program_id() == future.program_id() { @@ -381,6 +393,7 @@ fn initialize_finalize_state<'a, N: Network>( transition_id, *future.function_name(), stack.get_finalize_types(future.function_name())?.clone(), + nonce, ); // Store the inputs. @@ -402,6 +415,7 @@ fn setup_await<'a, N: Network>( stack: &'a Stack, registers: &FinalizeRegisters, transition_id: N::TransitionID, + nonce: u64, ) -> Result> { // Retrieve the input as a future. let future = match registers.load(stack, &Operand::Register(await_.register().clone()))? { @@ -409,7 +423,7 @@ fn setup_await<'a, N: Network>( _ => bail!("The input to 'await' is not a future"), }; // Initialize the state. - initialize_finalize_state(state, &future, stack, transition_id) + initialize_finalize_state(state, &future, stack, transition_id, nonce) } // A helper function that returns the index to branch to. @@ -444,6 +458,31 @@ fn branch_to( } } +// A helper function to compute the transition ID for the finalize registers. +fn finalize_transition_id( + state: &FinalizeGlobalState, + call_graph: &HashMap>, + call_counter: usize, + transition_id: N::TransitionID, +) -> Result { + if state.block_height() > N::CONSENSUS_V2_HEIGHT { + transition_id + } else { + // If the block height is greater than + // Get the current transition ID. + let transition_id = registers.transition_id(); + // Get the child transition ID. + let finalize_transition_id = match call_graph.get(transition_id) { + Some(transitions) => match transitions.get(call_counter) { + Some(transition_id) => *transition_id, + None => bail!("Child transition ID not found."), + }, + None => bail!("Transition ID '{transition_id}' not found in call graph"), + }; + Ok(finalize_transition_id) + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/synthesizer/process/src/stack/finalize_registers/mod.rs b/synthesizer/process/src/stack/finalize_registers/mod.rs index ccc02fd42d..c86a1d35c2 100644 --- a/synthesizer/process/src/stack/finalize_registers/mod.rs +++ b/synthesizer/process/src/stack/finalize_registers/mod.rs @@ -46,6 +46,8 @@ pub struct FinalizeRegisters { finalize_types: FinalizeTypes, /// The mapping of assigned registers to their values. registers: IndexMap>, + /// A nonce for finalize registers. + nonce: u64, /// The tracker for the last register locator. last_register: Option, } @@ -58,8 +60,17 @@ impl FinalizeRegisters { transition_id: N::TransitionID, function_name: Identifier, finalize_types: FinalizeTypes, + nonce: u64, ) -> Self { - Self { state, transition_id, finalize_types, function_name, registers: IndexMap::new(), last_register: None } + Self { + state, + transition_id, + finalize_types, + function_name, + registers: IndexMap::new(), + nonce, + last_register: None, + } } } @@ -81,4 +92,10 @@ impl FinalizeRegistersState for FinalizeRegisters { fn function_name(&self) -> &Identifier { &self.function_name } + + /// Returns the nonce for the finalize registers. + #[inline] + fn nonce(&self) -> u64 { + self.nonce + } } diff --git a/synthesizer/process/src/stack/register_types/initialize.rs b/synthesizer/process/src/stack/register_types/initialize.rs index 3714852a3a..82bb47422e 100644 --- a/synthesizer/process/src/stack/register_types/initialize.rs +++ b/synthesizer/process/src/stack/register_types/initialize.rs @@ -158,7 +158,7 @@ impl RegisterTypes { } /* Additional checks. */ - // - All futures produces before the `async` call must be consumed by the `async` call. + // - All futures produced before the `async` call must be consumed by the `async` call. // Get all registers containing futures. let mut future_registers: IndexSet<(Register, Locator)> = register_types diff --git a/synthesizer/program/src/logic/command/rand_chacha.rs b/synthesizer/program/src/logic/command/rand_chacha.rs index 44aa938c97..4351c753d9 100644 --- a/synthesizer/program/src/logic/command/rand_chacha.rs +++ b/synthesizer/program/src/logic/command/rand_chacha.rs @@ -89,15 +89,28 @@ impl RandChaCha { let seeds: Vec<_> = self.operands.iter().map(|operand| registers.load(stack, operand)).try_collect()?; // Construct the random seed. - let preimage = to_bits_le![ - registers.state().random_seed(), - **registers.transition_id(), - stack.program_id(), - registers.function_name(), - self.destination.locator(), - self.destination_type.type_id(), - seeds - ]; + let preimage = if registers.state().block_height() >= N::CONSENSUS_V2_HEIGHT { + to_bits_le![ + registers.state().random_seed(), + **registers.transition_id(), + stack.program_id(), + registers.function_name(), + registers.nonce(), + self.destination.locator(), + self.destination_type.type_id(), + seeds + ] + } else { + to_bits_le![ + registers.state().random_seed(), + **registers.transition_id(), + stack.program_id(), + registers.function_name(), + self.destination.locator(), + self.destination_type.type_id(), + seeds + ] + }; // Hash the preimage. let digest = N::hash_bhp1024(&preimage)?.to_bytes_le()?; diff --git a/synthesizer/program/src/traits/stack_and_registers.rs b/synthesizer/program/src/traits/stack_and_registers.rs index 459a064b39..f9b7ec5c54 100644 --- a/synthesizer/program/src/traits/stack_and_registers.rs +++ b/synthesizer/program/src/traits/stack_and_registers.rs @@ -120,6 +120,9 @@ pub trait FinalizeRegistersState { /// Returns the function name for the finalize scope. fn function_name(&self) -> &Identifier; + + /// Returns the nonce for the finalize registers. + fn nonce(&self) -> u64; } pub trait RegistersSigner { diff --git a/synthesizer/program/tests/helpers/sample.rs b/synthesizer/program/tests/helpers/sample.rs index 4f6395125b..c6a11031a1 100644 --- a/synthesizer/program/tests/helpers/sample.rs +++ b/synthesizer/program/tests/helpers/sample.rs @@ -73,6 +73,7 @@ pub fn sample_finalize_registers( ::TransitionID::default(), *function_name, stack.get_finalize_types(function_name)?.clone(), + 0u64, ); // For each literal, diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out new file mode 100644 index 0000000000..9035af0312 --- /dev/null +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out @@ -0,0 +1,25 @@ +errors: [] +outputs: +- verified: true + execute: + outer.aleo/call_mid: + outputs: + - '{"type":"public","id":"2301587965105966754142050666046677107364996949797815128474709473266430416696field","value":"1000000field"}' + - '{"type":"future","id":"4716145591704663568310612342512104696544794498128591386306943309631776159538field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted + add_next_block: succeeded. +additional: +- child_outputs: + nofin.aleo/do: + outputs: + - '{"type":"public","id":"2810059825165621756282482599752302608445186100857886652592226912460016272227field","value":"1000000field"}' + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"6884849811807685148611729637432856195626491894347218521923234795128862008412field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"public","id":"7516379094769281711358210337281452603173569591363079692252867720859252600938field","value":"0field"}' + - '{"type":"future","id":"1742421082873735534027207523675220648019822559721953111508825497611161628034field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"553990883457289109173422070562273818924424033377397745297633641139928117144field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo new file mode 100644 index 0000000000..931f9f9e6c --- /dev/null +++ b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo @@ -0,0 +1,86 @@ +/* +randomness: 402893173 +cases: + - program: outer.aleo + function: call_mid + inputs: [0field] +*/ + +program nofin.aleo; + +function do: + input r0 as field.public; + mul r0 100field into r1; + output r1 as field.public; + +///////////////////////////////////////////////// + +program inner.aleo; + +mapping rand_store: + key as u8.public; + value as u128.public; + +function save_inner_rand: + input r0 as field.public; + async save_inner_rand r0 into r1; + output r1 as inner.aleo/save_inner_rand.future; + +finalize save_inner_rand: + input r0 as field.public; + rand.chacha r0 into r1 as u128; + set r1 into rand_store[0u8]; + +///////////////////////////////////////////////// + +import inner.aleo; +import nofin.aleo; + +program mid.aleo; + +mapping rand_store: + key as u8.public; + value as u128.public; + +function save_mid_rand: + input r0 as field.public; + call nofin.aleo/do r0 into r1; + call inner.aleo/save_inner_rand r1 into r2; + call nofin.aleo/do r1 into r3; + async save_mid_rand r2 into r4; + output r3 as field.public; + output r4 as mid.aleo/save_mid_rand.future; + +finalize save_mid_rand: + input r0 as inner.aleo/save_inner_rand.future; + await r0; + rand.chacha into r1 as u128; + set r1 into rand_store[0u8]; + + +///////////////////////////////////////////////// + +import inner.aleo; +import nofin.aleo; +import mid.aleo; + +program outer.aleo; + +function call_mid: + input r0 as field.public; + add r0 1field into r1; + call nofin.aleo/do r1 into r2; + call mid.aleo/save_mid_rand r0 into r3 r4; + call nofin.aleo/do r2 into r5; + call mid.aleo/save_mid_rand r3 into r6 r7; + call nofin.aleo/do r5 into r8; + async call_mid r4 r7 into r9; + output r8 as field.public; + output r9 as outer.aleo/call_mid.future; + +finalize call_mid: + input r0 as mid.aleo/save_mid_rand.future; + input r1 as mid.aleo/save_mid_rand.future; + await r0; + await r1; + From 78bce6f10cdd3cd188b355bf7dbb59680a08957c Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:37:16 -0800 Subject: [PATCH 02/13] Fix test configuration --- synthesizer/Cargo.toml | 2 +- synthesizer/process/src/finalize.rs | 29 +++-- .../complex_finalization_2.out | 112 ++++++++++++++++++ .../complex_finalization_2.aleo | 2 + 4 files changed, 131 insertions(+), 14 deletions(-) diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 8ce6d33350..608d4e31c4 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -44,7 +44,7 @@ serial = [ "synthesizer-snark/serial" ] setup = [ ] -test = [ ] +test = [ "console/test", "ledger-block/test", "ledger-store/test" ] timer = [ "aleo-std/timer" ] wasm = [ "process", diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 6cabeac393..1bb0a5ce39 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -104,7 +104,7 @@ impl Process { lap!(timer, "Verify the number of transitions"); // Construct the call graph. - let call_graph = if state.block_height() > N::CONSENSUS_V2_HEIGHT { + let call_graph = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { Default::default() } else { self.construct_call_graph(execution)? @@ -164,10 +164,12 @@ fn finalize_fee_transition>( fee: &Fee, ) -> Result>> { // Construct the call graph. - let call_graph = if state.block_height() > N::CONSENSUS_V2_HEIGHT { + let call_graph = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { Default::default() } else { - HashMap::from([*fee.transition_id(), Vec::new()]) + let mut call_graph = HashMap::new(); + call_graph.insert(*fee.transition_id(), vec![]); + call_graph }; // Finalize the transition. @@ -272,9 +274,9 @@ fn finalize_transition>( await_.register() ); - // Get the finalize transition ID. - let finalize_transition_id = - finalize_transition_id(&state, &call_graph, call_counter, *transition.id())?; + // Get the child transition ID. + let child_transition_id = + child_transition_id::(&state, ®isters, &call_graph, *transition.id(), call_counter)?; // Increment the nonce. nonce += 1; @@ -285,7 +287,7 @@ fn finalize_transition>( await_, stack, ®isters, - finalize_transition_id, + child_transition_id, nonce )) { Ok(Ok(callee_state)) => callee_state, @@ -459,27 +461,28 @@ fn branch_to( } // A helper function to compute the transition ID for the finalize registers. -fn finalize_transition_id( +fn child_transition_id( state: &FinalizeGlobalState, + registers: &FinalizeRegisters, call_graph: &HashMap>, - call_counter: usize, transition_id: N::TransitionID, + call_counter: usize, ) -> Result { - if state.block_height() > N::CONSENSUS_V2_HEIGHT { - transition_id + if state.block_height() >= N::CONSENSUS_V2_HEIGHT { + Ok(transition_id) } else { // If the block height is greater than // Get the current transition ID. let transition_id = registers.transition_id(); // Get the child transition ID. - let finalize_transition_id = match call_graph.get(transition_id) { + let child_transition_id = match call_graph.get(&transition_id) { Some(transitions) => match transitions.get(call_counter) { Some(transition_id) => *transition_id, None => bail!("Child transition ID not found."), }, None => bail!("Transition ID '{transition_id}' not found in call graph"), }; - Ok(finalize_transition_id) + Ok(child_transition_id) } } diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out index 9035af0312..732dbbdaae 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out @@ -8,6 +8,68 @@ outputs: - '{"type":"future","id":"4716145591704663568310612342512104696544794498128591386306943309631776159538field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/call_mid: + outputs: + - '{"type":"public","id":"7110762622677581603531784592296843981170341491118135783057018274324153733352field","value":"1000000field"}' + - '{"type":"future","id":"6821474241879311963514314332414105369461141549565763943585181899878549264506field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted + add_next_block: succeeded. additional: - child_outputs: nofin.aleo/do: @@ -23,3 +85,53 @@ additional: credits.aleo/fee_public: outputs: - '{"type":"future","id":"553990883457289109173422070562273818924424033377397745297633641139928117144field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"6036871241297314677434211732180033747339195052768397229090564832759530086268field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"239843448734063574186492246693249869581510666120842966198758931160658860229field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"5788520230963101338089956859503070238680165817984702773865998735224927312622field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"5815519700770547633298030580799588270852844151427463072347465350400217642539field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"4331619254812630927856323717820733239252810213237999078535809533102252695318field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"1627585082115216484938472130883963045156742388438162671678551848326664192934field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"6511764724577381617224389166578143266631687208210016079255307080810188103259field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"4146983181500561396028053076736451753290432488407271060918694850408263352074field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"1972393642715895432506562763467214235681507491122287713249983565316761650387field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + nofin.aleo/do: + outputs: + - '{"type":"public","id":"2300714828846788615312875213669401865129232300079608172608075584890556454224field","value":"1000000field"}' + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"2233667438183954481330343819743788819489975463040330279760558820330494882751field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"public","id":"2892068528571964889323978466428825367547475182212918901965548845057648135543field","value":"0field"}' + - '{"type":"future","id":"7749198124204675610518517378413586217782525994229500176420775452237824057586field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"5715233362353473909844883632298385458478203456274921711723986031518103765822field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo index 931f9f9e6c..6b4cded994 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo @@ -84,3 +84,5 @@ finalize call_mid: await r0; await r1; +function dummy: + From de6c852187fded058a39823df357223068560ba8 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 11 Nov 2024 14:55:53 -0800 Subject: [PATCH 03/13] Update --- .../complex_finalization_2.out | 112 ------------------ 1 file changed, 112 deletions(-) diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out index 732dbbdaae..9035af0312 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out @@ -8,68 +8,6 @@ outputs: - '{"type":"future","id":"4716145591704663568310612342512104696544794498128591386306943309631776159538field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted - add_next_block: succeeded. -- verified: true - execute: - outer.aleo/call_mid: - outputs: - - '{"type":"public","id":"7110762622677581603531784592296843981170341491118135783057018274324153733352field","value":"1000000field"}' - - '{"type":"future","id":"6821474241879311963514314332414105369461141549565763943585181899878549264506field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' - speculate: the execution was accepted - add_next_block: succeeded. additional: - child_outputs: nofin.aleo/do: @@ -85,53 +23,3 @@ additional: credits.aleo/fee_public: outputs: - '{"type":"future","id":"553990883457289109173422070562273818924424033377397745297633641139928117144field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"6036871241297314677434211732180033747339195052768397229090564832759530086268field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"239843448734063574186492246693249869581510666120842966198758931160658860229field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"5788520230963101338089956859503070238680165817984702773865998735224927312622field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"5815519700770547633298030580799588270852844151427463072347465350400217642539field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"4331619254812630927856323717820733239252810213237999078535809533102252695318field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"1627585082115216484938472130883963045156742388438162671678551848326664192934field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"6511764724577381617224389166578143266631687208210016079255307080810188103259field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"4146983181500561396028053076736451753290432488407271060918694850408263352074field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"1972393642715895432506562763467214235681507491122287713249983565316761650387field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' -- child_outputs: - nofin.aleo/do: - outputs: - - '{"type":"public","id":"2300714828846788615312875213669401865129232300079608172608075584890556454224field","value":"1000000field"}' - inner.aleo/save_inner_rand: - outputs: - - '{"type":"future","id":"2233667438183954481330343819743788819489975463040330279760558820330494882751field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' - mid.aleo/save_mid_rand: - outputs: - - '{"type":"public","id":"2892068528571964889323978466428825367547475182212918901965548845057648135543field","value":"0field"}' - - '{"type":"future","id":"7749198124204675610518517378413586217782525994229500176420775452237824057586field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' - credits.aleo/fee_public: - outputs: - - '{"type":"future","id":"5715233362353473909844883632298385458478203456274921711723986031518103765822field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' From 230e99586fded1e10a5aa848e180695fb385a4e0 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:51:29 -0800 Subject: [PATCH 04/13] Update test cases --- .../complex_finalization_2.out | 36 +++++++++++++++---- .../complex_finalization_2.aleo | 21 +++++++++++ 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out index 9035af0312..a0beeae8d4 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out @@ -4,22 +4,44 @@ outputs: execute: outer.aleo/call_mid: outputs: - - '{"type":"public","id":"2301587965105966754142050666046677107364996949797815128474709473266430416696field","value":"1000000field"}' - - '{"type":"future","id":"4716145591704663568310612342512104696544794498128591386306943309631776159538field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + - '{"type":"public","id":"8105804501865877013475085181603622803640937752638753075245651882766436423349field","value":"1000000field"}' + - '{"type":"future","id":"3872609744211560970368504701842445486396917484377889002749887052266678172302field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/call_mid_2: + outputs: + - '{"type":"public","id":"4453636188261953706563089747775655639454482040048987202675112807284591190856field","value":"1000000field"}' + - '{"type":"future","id":"1849434560331700046156403375777731811054018328898174649421388394846056123144field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: nofin.aleo/do: outputs: - - '{"type":"public","id":"2810059825165621756282482599752302608445186100857886652592226912460016272227field","value":"1000000field"}' + - '{"type":"public","id":"869832116858831069177257795886179043632637701198137960449625733496221546067field","value":"1000000field"}' + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"3416670234272847313643302698471106120191742548263742133125282315524560079087field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"public","id":"4290978704981802392060575457241727517526159930290379639350020816440252908068field","value":"0field"}' + - '{"type":"future","id":"7252915948751263188651880927011336156291243389490225062836163979730836991001field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"416417237245104126591912054470133832645607654224123918868643114512964938492field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' +- child_outputs: + nofin.aleo/do: + outputs: + - '{"type":"public","id":"4627368060462894640208667339567816653873125644105280849967786774285329777105field","value":"1000000field"}' inner.aleo/save_inner_rand: outputs: - - '{"type":"future","id":"6884849811807685148611729637432856195626491894347218521923234795128862008412field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + - '{"type":"future","id":"6152773655125421284017065685977525395337277041506710065301622782501596462737field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' mid.aleo/save_mid_rand: outputs: - - '{"type":"public","id":"7516379094769281711358210337281452603173569591363079692252867720859252600938field","value":"0field"}' - - '{"type":"future","id":"1742421082873735534027207523675220648019822559721953111508825497611161628034field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + - '{"type":"public","id":"6304435715203809693309237319186246240313545715798350240468102739905698229982field","value":"0field"}' + - '{"type":"future","id":"7547342076265501534059602542343480398739151332622584733924827807391822727883field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"553990883457289109173422070562273818924424033377397745297633641139928117144field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' + - '{"type":"future","id":"2311133970540220747295460072634292664035273264774408144553377087053617272572field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160415u64\n ]\n}"}' diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo index 6b4cded994..98f53480e8 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo @@ -4,6 +4,9 @@ cases: - program: outer.aleo function: call_mid inputs: [0field] + - program: outer.aleo + function: call_mid_2 + inputs: [0field] */ program nofin.aleo; @@ -84,5 +87,23 @@ finalize call_mid: await r0; await r1; +function call_mid_2: + input r0 as field.public; + add r0 1field into r1; + call nofin.aleo/do r1 into r2; + call mid.aleo/save_mid_rand r0 into r3 r4; + call nofin.aleo/do r2 into r5; + call mid.aleo/save_mid_rand r3 into r6 r7; + call nofin.aleo/do r5 into r8; + async call_mid_2 r4 r7 into r9; + output r8 as field.public; + output r9 as outer.aleo/call_mid_2.future; + +finalize call_mid_2: + input r0 as mid.aleo/save_mid_rand.future; + input r1 as mid.aleo/save_mid_rand.future; + await r1; + await r0; + function dummy: From 3fc729faf127bda2609112e6cc1e00b3b389a9ac Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 11 Nov 2024 17:06:58 -0800 Subject: [PATCH 05/13] Update CI conf --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4aad608529..dba6cf51d1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -692,7 +692,7 @@ jobs: resource_class: << pipeline.parameters.twoxlarge >> steps: - run_serial: - flags: --test '*' -- --test-threads=8 + flags: --test '*' --features test -- --test-threads=8 workspace_member: synthesizer cache_key: v1.0.0-rust-1.81.0-snarkvm-synthesizer-integration-cache From df6a4849e15433b695fd93296937afcf5db89594 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:14:13 -0800 Subject: [PATCH 06/13] Update test case and address initial feedback --- console/network/src/canary_v0.rs | 2 +- console/network/src/mainnet_v0.rs | 2 +- synthesizer/process/src/finalize.rs | 68 ++++++----------- .../complex_finalization_2.out | 76 ++++++++++++++++++- .../complex_finalization_2.aleo | 15 ++++ 5 files changed, 117 insertions(+), 46 deletions(-) diff --git a/console/network/src/canary_v0.rs b/console/network/src/canary_v0.rs index 5aae6930ef..f2227a72f4 100644 --- a/console/network/src/canary_v0.rs +++ b/console/network/src/canary_v0.rs @@ -139,7 +139,7 @@ impl Network for CanaryV0 { // TODO (raychu86): Update this value based on the desired canary height. /// The block height from which consensus V2 rules apply. #[cfg(any(test, feature = "test"))] - const CONSENSUS_V2_HEIGHT: u32 = 0; + const CONSENSUS_V2_HEIGHT: u32 = 10; /// The network edition. const EDITION: u16 = 0; /// The genesis block coinbase target. diff --git a/console/network/src/mainnet_v0.rs b/console/network/src/mainnet_v0.rs index 40e3013b09..b38e59b2c9 100644 --- a/console/network/src/mainnet_v0.rs +++ b/console/network/src/mainnet_v0.rs @@ -140,7 +140,7 @@ impl Network for MainnetV0 { // TODO (raychu86): Update this value based on the desired mainnet height. /// The block height from which consensus V2 rules apply. #[cfg(any(test, feature = "test"))] - const CONSENSUS_V2_HEIGHT: u32 = 0; + const CONSENSUS_V2_HEIGHT: u32 = 10; /// The network edition. const EDITION: u16 = 0; /// The genesis block coinbase target. diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 1bb0a5ce39..101b221316 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -274,28 +274,36 @@ fn finalize_transition>( await_.register() ); - // Get the child transition ID. - let child_transition_id = - child_transition_id::(&state, ®isters, &call_graph, *transition.id(), call_counter)?; + // Get the transition ID used to initialize the finalize registers. + // If the block height is greater than the consensus V2 height, return the main transition ID. + // Otherwise, query the call graph for the child transition ID corresponding to the future that is being awaited. + let transition_id = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { + *transition.id() + } else { + // Get the current transition ID. + let transition_id = registers.transition_id(); + // Get the child transition ID. + match call_graph.get(transition_id) { + Some(transitions) => match transitions.get(call_counter) { + Some(transition_id) => *transition_id, + None => bail!("Child transition ID not found."), + }, + None => bail!("Transition ID '{transition_id}' not found in call graph"), + } + }; // Increment the nonce. nonce += 1; // Set up the finalize state for the await. - let callee_state = match try_vm_runtime!(|| setup_await( - state, - await_, - stack, - ®isters, - child_transition_id, - nonce - )) { - Ok(Ok(callee_state)) => callee_state, - // If the evaluation fails, bail and return the error. - Ok(Err(error)) => bail!("'finalize' failed to evaluate command ({command}): {error}"), - // If the evaluation fails, bail and return the error. - Err(_) => bail!("'finalize' failed to evaluate command ({command})"), - }; + let callee_state = + match try_vm_runtime!(|| setup_await(state, await_, stack, ®isters, transition_id, nonce)) { + Ok(Ok(callee_state)) => callee_state, + // If the evaluation fails, bail and return the error. + Ok(Err(error)) => bail!("'finalize' failed to evaluate command ({command}): {error}"), + // If the evaluation fails, bail and return the error. + Err(_) => bail!("'finalize' failed to evaluate command ({command})"), + }; // Increment the call counter. call_counter += 1; @@ -460,32 +468,6 @@ fn branch_to( } } -// A helper function to compute the transition ID for the finalize registers. -fn child_transition_id( - state: &FinalizeGlobalState, - registers: &FinalizeRegisters, - call_graph: &HashMap>, - transition_id: N::TransitionID, - call_counter: usize, -) -> Result { - if state.block_height() >= N::CONSENSUS_V2_HEIGHT { - Ok(transition_id) - } else { - // If the block height is greater than - // Get the current transition ID. - let transition_id = registers.transition_id(); - // Get the child transition ID. - let child_transition_id = match call_graph.get(&transition_id) { - Some(transitions) => match transitions.get(call_counter) { - Some(transition_id) => *transition_id, - None => bail!("Child transition ID not found."), - }, - None => bail!("Transition ID '{transition_id}' not found in call graph"), - }; - Ok(child_transition_id) - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out index a0beeae8d4..a8898c2a3c 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out @@ -6,7 +6,7 @@ outputs: outputs: - '{"type":"public","id":"8105804501865877013475085181603622803640937752638753075245651882766436423349field","value":"1000000field"}' - '{"type":"future","id":"3872609744211560970368504701842445486396917484377889002749887052266678172302field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' - speculate: the execution was accepted + speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: @@ -14,6 +14,40 @@ outputs: outputs: - '{"type":"public","id":"4453636188261953706563089747775655639454482040048987202675112807284591190856field","value":"1000000field"}' - '{"type":"future","id":"1849434560331700046156403375777731811054018328898174649421388394846056123144field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was rejected + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/dummy: + outputs: [] + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/call_mid: + outputs: + - '{"type":"public","id":"1881008346238905235680497431781788217927766201760626741672120752039275408357field","value":"1000000field"}' + - '{"type":"future","id":"3973426767978794150806915362267994205013483553379622291420618294309240156097field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/call_mid_2: + outputs: + - '{"type":"public","id":"2246856398831486445779453325451073351797474022748139484560427521724603779462field","value":"1000000field"}' + - '{"type":"future","id":"2950639418084310390234423398356835122011322621456564877497427953064866911068field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: @@ -45,3 +79,43 @@ additional: credits.aleo/fee_public: outputs: - '{"type":"future","id":"2311133970540220747295460072634292664035273264774408144553377087053617272572field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160415u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"7495243840470670592466994904621312774594300812745497502859134506122343941452field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"2175759062123847325921919658496101458036093092082217212502708037221890199855field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"6194763244383380375407778496857186996903616164599482246071751164326478513956field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' +- child_outputs: + nofin.aleo/do: + outputs: + - '{"type":"public","id":"67936315122841170023459432877439742803601898651242119476568618765199519430field","value":"1000000field"}' + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"3008093629640919426745129536771146558553774436172156183909825545867866684606field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"public","id":"3047418466290764760483002802348579079880087072839255535391455878637369760988field","value":"0field"}' + - '{"type":"future","id":"5806974430145676996806632418166295399555849607133087600416545076969313091753field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"2292421221438565837366285313023762364541343158325931716414813013279478927418field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' +- child_outputs: + nofin.aleo/do: + outputs: + - '{"type":"public","id":"3267294547715279195297543176041462685144029647699230304961995527524257563574field","value":"1000000field"}' + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"3489966301860448758037932249180236645202339313783249292059413758478781729124field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"public","id":"6351013134792512420738314586135764345515972465552962290349592476475822002774field","value":"0field"}' + - '{"type":"future","id":"5179880583079956902228123669374600662410201344199319348611907299661376971651field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + credits.aleo/fee_public: + outputs: + - '{"type":"future","id":"3999904529968759047212365836988076999942390013044466367862930533200140942991field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160415u64\n ]\n}"}' diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo index 98f53480e8..2dfcab2c20 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo @@ -7,6 +7,21 @@ cases: - program: outer.aleo function: call_mid_2 inputs: [0field] + - program: outer.aleo + function: dummy + inputs: [] + - program: outer.aleo + function: dummy + inputs: [] + - program: outer.aleo + function: dummy + inputs: [] + - program: outer.aleo + function: call_mid + inputs: [0field] + - program: outer.aleo + function: call_mid_2 + inputs: [0field] */ program nofin.aleo; From 5a72fea066fd3dc98092d02d0f9ff827e0e86654 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Tue, 12 Nov 2024 19:01:14 -0800 Subject: [PATCH 07/13] Regen expectations --- .../tests/expectations/vm/execute_and_finalize/test_rand.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out index 6380117c04..0af538e48d 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/test_rand.out @@ -26,7 +26,7 @@ outputs: test_rand.aleo/rand_chacha_check: outputs: - '{"type":"future","id":"818878742790741579153893179075772445872751227433677932822653185952935999557field","value":"{\n program_id: test_rand.aleo,\n function_name: rand_chacha_check,\n arguments: [\n 1field,\n true\n ]\n}"}' - speculate: the execution was rejected + speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: From e9fad83394ca68a1d009495ec497c809f14d7a6e Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:17:46 -0800 Subject: [PATCH 08/13] Simplify example for more clarity --- ...out => interleave_async_and_non_async.out} | 97 +++++++++++-------- ...eo => interleave_async_and_non_async.aleo} | 95 ++++++++++-------- 2 files changed, 110 insertions(+), 82 deletions(-) rename synthesizer/tests/expectations/vm/execute_and_finalize/{complex_finalization_2.out => interleave_async_and_non_async.out} (54%) rename synthesizer/tests/tests/vm/execute_and_finalize/{complex_finalization_2.aleo => interleave_async_and_non_async.aleo} (50%) diff --git a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out b/synthesizer/tests/expectations/vm/execute_and_finalize/interleave_async_and_non_async.out similarity index 54% rename from synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out rename to synthesizer/tests/expectations/vm/execute_and_finalize/interleave_async_and_non_async.out index a8898c2a3c..ea6868cce5 100644 --- a/synthesizer/tests/expectations/vm/execute_and_finalize/complex_finalization_2.out +++ b/synthesizer/tests/expectations/vm/execute_and_finalize/interleave_async_and_non_async.out @@ -2,25 +2,31 @@ errors: [] outputs: - verified: true execute: - outer.aleo/call_mid: + mid.aleo/save_mid_rand_2: outputs: - - '{"type":"public","id":"8105804501865877013475085181603622803640937752638753075245651882766436423349field","value":"1000000field"}' - - '{"type":"future","id":"3872609744211560970368504701842445486396917484377889002749887052266678172302field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' - speculate: the execution was rejected + - '{"type":"future","id":"8133252294099058744569698548841506104644319254713927471060413341001678088866field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand_2,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: - outer.aleo/call_mid_2: + outer.aleo/call_mid_3: outputs: - - '{"type":"public","id":"4453636188261953706563089747775655639454482040048987202675112807284591190856field","value":"1000000field"}' - - '{"type":"future","id":"1849434560331700046156403375777731811054018328898174649421388394846056123144field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"3943339733672692638395740341671994092158484825516042860641043685177097488932field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_3,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was accepted + add_next_block: succeeded. +- verified: true + execute: + outer.aleo/call_mid: + outputs: + - '{"type":"future","id":"3234621292740822058818055697198799540048108651323455396840123946866280290387field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: - outer.aleo/dummy: - outputs: [] - speculate: the execution was accepted + outer.aleo/call_mid_2: + outputs: + - '{"type":"future","id":"6256136872031781770553816141201857256304896691884762229618319303437235049235field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + speculate: the execution was rejected add_next_block: succeeded. - verified: true execute: @@ -38,51 +44,62 @@ outputs: execute: outer.aleo/call_mid: outputs: - - '{"type":"public","id":"1881008346238905235680497431781788217927766201760626741672120752039275408357field","value":"1000000field"}' - - '{"type":"future","id":"3973426767978794150806915362267994205013483553379622291420618294309240156097field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"1306093314372315683199201111238004382243599558432936764134146620392309864825field","value":"{\n program_id: outer.aleo,\n function_name: call_mid,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. - verified: true execute: outer.aleo/call_mid_2: outputs: - - '{"type":"public","id":"2246856398831486445779453325451073351797474022748139484560427521724603779462field","value":"1000000field"}' - - '{"type":"future","id":"2950639418084310390234423398356835122011322621456564877497427953064866911068field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"5339203461188730231977055323402789013912803000568623987257194255574835631870field","value":"{\n program_id: outer.aleo,\n function_name: call_mid_2,\n arguments: [\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n },\n {\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n }\n \n ]\n}"}' speculate: the execution was accepted add_next_block: succeeded. additional: - child_outputs: - nofin.aleo/do: + inner.aleo/dummy: + outputs: [] + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"2491454043368457724827856328992492378252414844160971129371068949933787800327field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + credits.aleo/fee_public: outputs: - - '{"type":"public","id":"869832116858831069177257795886179043632637701198137960449625733496221546067field","value":"1000000field"}' + - '{"type":"future","id":"8364085965948136284430782264975904513362941894972177369414604763679081824990field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 76697u64\n ]\n}"}' +- child_outputs: inner.aleo/save_inner_rand: outputs: - - '{"type":"future","id":"3416670234272847313643302698471106120191742548263742133125282315524560079087field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + - '{"type":"future","id":"5529824764130005030074933219733459982343596117334741286429948259175211128460field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' mid.aleo/save_mid_rand: outputs: - - '{"type":"public","id":"4290978704981802392060575457241727517526159930290379639350020816440252908068field","value":"0field"}' - - '{"type":"future","id":"7252915948751263188651880927011336156291243389490225062836163979730836991001field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"4360736171399918590300263879039970750359601853381250666126605518412297988622field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + mid.aleo/dummy: + outputs: [] credits.aleo/fee_public: outputs: - - '{"type":"future","id":"416417237245104126591912054470133832645607654224123918868643114512964938492field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' + - '{"type":"future","id":"115907321802783128984566810198532384178634534374658674607472564056856197283field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 153515u64\n ]\n}"}' - child_outputs: - nofin.aleo/do: - outputs: - - '{"type":"public","id":"4627368060462894640208667339567816653873125644105280849967786774285329777105field","value":"1000000field"}' + mid.aleo/dummy: + outputs: [] inner.aleo/save_inner_rand: outputs: - - '{"type":"future","id":"6152773655125421284017065685977525395337277041506710065301622782501596462737field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + - '{"type":"future","id":"4614422449220197915414605795206400101815072983960277710851966783861356960406field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' mid.aleo/save_mid_rand: outputs: - - '{"type":"public","id":"6304435715203809693309237319186246240313545715798350240468102739905698229982field","value":"0field"}' - - '{"type":"future","id":"7547342076265501534059602542343480398739151332622584733924827807391822727883field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"2508191276062236001575741846287485044265199754282255664177008646882560557252field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2311133970540220747295460072634292664035273264774408144553377087053617272572field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160415u64\n ]\n}"}' + - '{"type":"future","id":"1073608049274464266751816702008249392786653692342830056680162189620354498415field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 78340u64\n ]\n}"}' - child_outputs: + inner.aleo/save_inner_rand: + outputs: + - '{"type":"future","id":"5225218680008854881439125057672129573587587270307645239381393215803081422716field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + mid.aleo/save_mid_rand: + outputs: + - '{"type":"future","id":"4178750000665019990650488851451367780305518344784410337482918142723400529474field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + mid.aleo/dummy: + outputs: [] credits.aleo/fee_public: outputs: - - '{"type":"future","id":"7495243840470670592466994904621312774594300812745497502859134506122343941452field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' + - '{"type":"future","id":"4292470820134718797108426369632556448016220649849044091832458381384800389195field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 153515u64\n ]\n}"}' - child_outputs: credits.aleo/fee_public: outputs: @@ -92,30 +109,26 @@ additional: outputs: - '{"type":"future","id":"6194763244383380375407778496857186996903616164599482246071751164326478513956field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 1140u64\n ]\n}"}' - child_outputs: - nofin.aleo/do: - outputs: - - '{"type":"public","id":"67936315122841170023459432877439742803601898651242119476568618765199519430field","value":"1000000field"}' + mid.aleo/dummy: + outputs: [] inner.aleo/save_inner_rand: outputs: - - '{"type":"future","id":"3008093629640919426745129536771146558553774436172156183909825545867866684606field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + - '{"type":"future","id":"4529862883499929835728878603802755394927344353486392225173072965224830358463field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' mid.aleo/save_mid_rand: outputs: - - '{"type":"public","id":"3047418466290764760483002802348579079880087072839255535391455878637369760988field","value":"0field"}' - - '{"type":"future","id":"5806974430145676996806632418166295399555849607133087600416545076969313091753field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"6229067068404597519789102533235527141806172689635987244039842690587924000396field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' credits.aleo/fee_public: outputs: - - '{"type":"future","id":"2292421221438565837366285313023762364541343158325931716414813013279478927418field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160403u64\n ]\n}"}' + - '{"type":"future","id":"8021075521801532321171456710878451353674458585397457916565042751752790326908field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 78340u64\n ]\n}"}' - child_outputs: - nofin.aleo/do: - outputs: - - '{"type":"public","id":"3267294547715279195297543176041462685144029647699230304961995527524257563574field","value":"1000000field"}' inner.aleo/save_inner_rand: outputs: - - '{"type":"future","id":"3489966301860448758037932249180236645202339313783249292059413758478781729124field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' + - '{"type":"future","id":"4658798592079913623338175453878141434944459064520081222639145355071325846611field","value":"{\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n}"}' mid.aleo/save_mid_rand: outputs: - - '{"type":"public","id":"6351013134792512420738314586135764345515972465552962290349592476475822002774field","value":"0field"}' - - '{"type":"future","id":"5179880583079956902228123669374600662410201344199319348611907299661376971651field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + - '{"type":"future","id":"3623884432182335762296151513319720627617987248182131956172560308625538161246field","value":"{\n program_id: mid.aleo,\n function_name: save_mid_rand,\n arguments: [\n {\n program_id: inner.aleo,\n function_name: save_inner_rand,\n arguments: [\n 0field\n ]\n }\n \n ]\n}"}' + mid.aleo/dummy: + outputs: [] credits.aleo/fee_public: outputs: - - '{"type":"future","id":"3999904529968759047212365836988076999942390013044466367862930533200140942991field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 160415u64\n ]\n}"}' + - '{"type":"future","id":"5680761132338633547187645063078428755949250696070829670269555126181522361675field","value":"{\n program_id: credits.aleo,\n function_name: fee_public,\n arguments: [\n aleo1dg8dpzx0d53ajd87nhppq79z9vrvhelhh45frsqkusndtaasgcxqqs0ay8,\n 153515u64\n ]\n}"}' diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo similarity index 50% rename from synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo rename to synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo index 2dfcab2c20..5f49b0dd7c 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/complex_finalization_2.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo @@ -1,6 +1,12 @@ /* randomness: 402893173 cases: + - program: mid.aleo + function: save_mid_rand_2 + inputs: [0field] + - program: outer.aleo + function: call_mid_3 + inputs: [0field] - program: outer.aleo function: call_mid inputs: [0field] @@ -13,9 +19,6 @@ cases: - program: outer.aleo function: dummy inputs: [] - - program: outer.aleo - function: dummy - inputs: [] - program: outer.aleo function: call_mid inputs: [0field] @@ -24,15 +27,6 @@ cases: inputs: [0field] */ -program nofin.aleo; - -function do: - input r0 as field.public; - mul r0 100field into r1; - output r1 as field.public; - -///////////////////////////////////////////////// - program inner.aleo; mapping rand_store: @@ -49,10 +43,11 @@ finalize save_inner_rand: rand.chacha r0 into r1 as u128; set r1 into rand_store[0u8]; +function dummy: + ///////////////////////////////////////////////// import inner.aleo; -import nofin.aleo; program mid.aleo; @@ -60,14 +55,12 @@ mapping rand_store: key as u8.public; value as u128.public; + function save_mid_rand: input r0 as field.public; - call nofin.aleo/do r0 into r1; - call inner.aleo/save_inner_rand r1 into r2; - call nofin.aleo/do r1 into r3; - async save_mid_rand r2 into r4; - output r3 as field.public; - output r4 as mid.aleo/save_mid_rand.future; + call inner.aleo/save_inner_rand r0 into r1; + async save_mid_rand r1 into r2; + output r2 as mid.aleo/save_mid_rand.future; finalize save_mid_rand: input r0 as inner.aleo/save_inner_rand.future; @@ -75,44 +68,51 @@ finalize save_mid_rand: rand.chacha into r1 as u128; set r1 into rand_store[0u8]; +// A call to `save_mid_rand_2` should be accepted because the non-async call is not a complex one. +function save_mid_rand_2: + input r0 as field.public; + call inner.aleo/dummy; + call inner.aleo/save_inner_rand r0 into r1; + async save_mid_rand_2 r1 into r2; + output r2 as mid.aleo/save_mid_rand_2.future; + +finalize save_mid_rand_2: + input r0 as inner.aleo/save_inner_rand.future; + await r0; + rand.chacha into r1 as u128; + set r1 into rand_store[0u8]; + +function dummy: + ///////////////////////////////////////////////// import inner.aleo; -import nofin.aleo; import mid.aleo; program outer.aleo; +// A call to `call_mid` should be rejected because the complex non-async call is before the async ones. function call_mid: input r0 as field.public; - add r0 1field into r1; - call nofin.aleo/do r1 into r2; - call mid.aleo/save_mid_rand r0 into r3 r4; - call nofin.aleo/do r2 into r5; - call mid.aleo/save_mid_rand r3 into r6 r7; - call nofin.aleo/do r5 into r8; - async call_mid r4 r7 into r9; - output r8 as field.public; - output r9 as outer.aleo/call_mid.future; + call mid.aleo/dummy; + call mid.aleo/save_mid_rand r0 into r1; + call mid.aleo/dummy; + async call_mid r1 into r2; + output r2 as outer.aleo/call_mid.future; finalize call_mid: input r0 as mid.aleo/save_mid_rand.future; - input r1 as mid.aleo/save_mid_rand.future; await r0; - await r1; +// A call to `call_mid_2` should be rejected because the complex non-async call is before the async ones. function call_mid_2: input r0 as field.public; - add r0 1field into r1; - call nofin.aleo/do r1 into r2; - call mid.aleo/save_mid_rand r0 into r3 r4; - call nofin.aleo/do r2 into r5; - call mid.aleo/save_mid_rand r3 into r6 r7; - call nofin.aleo/do r5 into r8; - async call_mid_2 r4 r7 into r9; - output r8 as field.public; - output r9 as outer.aleo/call_mid_2.future; + call mid.aleo/save_mid_rand r0 into r1; + call mid.aleo/dummy; + call mid.aleo/save_mid_rand r0 into r2; + async call_mid_2 r1 r2 into r3; + output r3 as outer.aleo/call_mid_2.future; finalize call_mid_2: input r0 as mid.aleo/save_mid_rand.future; @@ -120,5 +120,20 @@ finalize call_mid_2: await r1; await r0; +// A call to `call_mid_3` should be accepted because the non-async call is after the async ones. +function call_mid_3: + input r0 as field.public; + call mid.aleo/save_mid_rand r0 into r1; + call mid.aleo/save_mid_rand r0 into r2; + call mid.aleo/dummy; + async call_mid_3 r1 r2 into r3; + output r3 as outer.aleo/call_mid_3.future; + +finalize call_mid_3: + input r0 as mid.aleo/save_mid_rand.future; + input r1 as mid.aleo/save_mid_rand.future; + await r1; + await r0; + function dummy: From 3fb928d56f2c7c2d1f5052ecc11514fcfa5625f2 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:37:19 -0800 Subject: [PATCH 09/13] Use CONSENSUS_V3_HEIGHT and address feedback --- synthesizer/process/src/finalize.rs | 8 ++++---- synthesizer/program/src/logic/command/rand_chacha.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 101b221316..4f4b4e41cf 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -104,7 +104,7 @@ impl Process { lap!(timer, "Verify the number of transitions"); // Construct the call graph. - let call_graph = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { + let call_graph = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { Default::default() } else { self.construct_call_graph(execution)? @@ -164,7 +164,7 @@ fn finalize_fee_transition>( fee: &Fee, ) -> Result>> { // Construct the call graph. - let call_graph = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { + let call_graph = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { Default::default() } else { let mut call_graph = HashMap::new(); @@ -275,9 +275,9 @@ fn finalize_transition>( ); // Get the transition ID used to initialize the finalize registers. - // If the block height is greater than the consensus V2 height, return the main transition ID. + // If the block height is greater than or equal to the consensus V3 height, return the main transition ID. // Otherwise, query the call graph for the child transition ID corresponding to the future that is being awaited. - let transition_id = if state.block_height() >= N::CONSENSUS_V2_HEIGHT { + let transition_id = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { *transition.id() } else { // Get the current transition ID. diff --git a/synthesizer/program/src/logic/command/rand_chacha.rs b/synthesizer/program/src/logic/command/rand_chacha.rs index 4351c753d9..f5e4fa7292 100644 --- a/synthesizer/program/src/logic/command/rand_chacha.rs +++ b/synthesizer/program/src/logic/command/rand_chacha.rs @@ -89,7 +89,7 @@ impl RandChaCha { let seeds: Vec<_> = self.operands.iter().map(|operand| registers.load(stack, operand)).try_collect()?; // Construct the random seed. - let preimage = if registers.state().block_height() >= N::CONSENSUS_V2_HEIGHT { + let preimage = if registers.state().block_height() >= N::CONSENSUS_V3_HEIGHT { to_bits_le![ registers.state().random_seed(), **registers.transition_id(), From 40e7f115e7d7fabca43a1e08e8c622617bcec8f2 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:38:53 -0800 Subject: [PATCH 10/13] Fmt --- console/network/src/canary_v0.rs | 10 ++++++++-- console/network/src/lib.rs | 2 ++ console/network/src/mainnet_v0.rs | 10 ++++++++-- console/network/src/testnet_v0.rs | 10 ++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/console/network/src/canary_v0.rs b/console/network/src/canary_v0.rs index f2227a72f4..22f342803d 100644 --- a/console/network/src/canary_v0.rs +++ b/console/network/src/canary_v0.rs @@ -136,10 +136,16 @@ impl Network for CanaryV0 { /// The block height from which consensus V2 rules apply. #[cfg(not(any(test, feature = "test")))] const CONSENSUS_V2_HEIGHT: u32 = 2_900_000; - // TODO (raychu86): Update this value based on the desired canary height. /// The block height from which consensus V2 rules apply. #[cfg(any(test, feature = "test"))] - const CONSENSUS_V2_HEIGHT: u32 = 10; + const CONSENSUS_V2_HEIGHT: u32 = 0; + // TODO: Update this value based on the desired canary height. + // The block height from which consensus V3 rules apply. + #[cfg(not(any(test, feature = "test")))] + const CONSENSUS_V3_HEIGHT: u32 = 3_900_000; + /// The block height from which consensus V3 rules apply. + #[cfg(any(test, feature = "test"))] + const CONSENSUS_V3_HEIGHT: u32 = 10; /// The network edition. const EDITION: u16 = 0; /// The genesis block coinbase target. diff --git a/console/network/src/lib.rs b/console/network/src/lib.rs index 8a627bafed..835860ff58 100644 --- a/console/network/src/lib.rs +++ b/console/network/src/lib.rs @@ -93,6 +93,8 @@ pub trait Network: /// The block height from which consensus V2 rules apply. const CONSENSUS_V2_HEIGHT: u32; + /// The block height from which consensus V3 rules apply. + const CONSENSUS_V3_HEIGHT: u32; /// The function name for the inclusion circuit. const INCLUSION_FUNCTION_NAME: &'static str; diff --git a/console/network/src/mainnet_v0.rs b/console/network/src/mainnet_v0.rs index b38e59b2c9..5b08c19401 100644 --- a/console/network/src/mainnet_v0.rs +++ b/console/network/src/mainnet_v0.rs @@ -137,10 +137,16 @@ impl Network for MainnetV0 { /// The block height from which consensus V2 rules apply. #[cfg(not(any(test, feature = "test")))] const CONSENSUS_V2_HEIGHT: u32 = 2_800_000; - // TODO (raychu86): Update this value based on the desired mainnet height. /// The block height from which consensus V2 rules apply. #[cfg(any(test, feature = "test"))] - const CONSENSUS_V2_HEIGHT: u32 = 10; + const CONSENSUS_V2_HEIGHT: u32 = 0; + // TODO: Update this value based on the desired mainnet height. + /// The block height from which consensus V3 rules apply. + #[cfg(not(any(test, feature = "test")))] + const CONSENSUS_V3_HEIGHT: u32 = 3_800_000; + /// The block height from which consensus V3 rules apply. + #[cfg(any(test, feature = "test"))] + const CONSENSUS_V3_HEIGHT: u32 = 10; /// The network edition. const EDITION: u16 = 0; /// The genesis block coinbase target. diff --git a/console/network/src/testnet_v0.rs b/console/network/src/testnet_v0.rs index 0e4e9d1cd7..f26a7345e0 100644 --- a/console/network/src/testnet_v0.rs +++ b/console/network/src/testnet_v0.rs @@ -136,10 +136,16 @@ impl Network for TestnetV0 { /// The block height from which consensus V2 rules apply. #[cfg(not(any(test, feature = "test")))] const CONSENSUS_V2_HEIGHT: u32 = 2_950_000; - // TODO (raychu86): Update this value based on the desired testnet height. /// The block height from which consensus V2 rules apply. #[cfg(any(test, feature = "test"))] - const CONSENSUS_V2_HEIGHT: u32 = 10; + const CONSENSUS_V2_HEIGHT: u32 = 0; + // TODO: Update this value based on the desired testnet height. + /// The block height from which consensus V3 rules apply. + #[cfg(not(any(test, feature = "test")))] + const CONSENSUS_V3_HEIGHT: u32 = 3_950_000; + /// The block height from which consensus V3 rules apply. + #[cfg(any(test, feature = "test"))] + const CONSENSUS_V3_HEIGHT: u32 = 10; /// The network edition. const EDITION: u16 = 0; /// The genesis block coinbase target. From 104432a051c125cd990dd5f103291b03fecd900d Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:24:13 -0800 Subject: [PATCH 11/13] Address feedback --- synthesizer/process/src/finalize.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 8c63f0a818..a7a2333174 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -167,9 +167,7 @@ fn finalize_fee_transition>( let call_graph = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { Default::default() } else { - let mut call_graph = HashMap::new(); - call_graph.insert(*fee.transition_id(), vec![]); - call_graph + HashMap::from([(*fee.transition_id(), Vec::new())]) }; // Finalize the transition. From 1af02b41abc867e7f2d4de78e642d5d3d8d50652 Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:27:24 -0800 Subject: [PATCH 12/13] Update test comment --- .../interleave_async_and_non_async.aleo | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo b/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo index a04f4c6a25..a06d369a3a 100644 --- a/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo +++ b/synthesizer/tests/tests/vm/execute_and_finalize/interleave_async_and_non_async.aleo @@ -95,7 +95,9 @@ import mid.aleo; program outer.aleo; -// A call to `call_mid` should be rejected because the complex non-async call is before the async ones. +// A call to `call_mid` will be rejected if called before the `CONSENSUS_V3_HEIGHT` because the complex non-async call +// is before the async ones, triggering a known failure. +// If it is called after the `CONSENSUS_V3_HEIGHT`, then it should be accepted. function call_mid: input r0 as field.public; call mid.aleo/dummy; @@ -108,7 +110,9 @@ finalize call_mid: input r0 as mid.aleo/save_mid_rand.future; await r0; -// A call to `call_mid_2` should be rejected because the complex non-async call is before the async ones. +// A call to `call_mid_2` will be rejected if called before the `CONSENSUS_V3_HEIGHT` because the complex non-async call +// is before the async ones, triggering a known failure. +// If it is called after the `CONSENSUS_V3_HEIGHT`, then it should be accepted. function call_mid_2: input r0 as field.public; call mid.aleo/save_mid_rand r0 into r1; From b6c98befe336aafd56c5f3ae42da19f33e5d47bc Mon Sep 17 00:00:00 2001 From: Pranav Gaddamadugu <23022326+d0cd@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:18:45 -0800 Subject: [PATCH 13/13] Address feedback, use less than for V3 height check for consistency --- synthesizer/process/src/finalize.rs | 44 ++++++++++--------- .../program/src/logic/command/rand_chacha.rs | 15 ++++--- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/synthesizer/process/src/finalize.rs b/synthesizer/process/src/finalize.rs index 65261c6b78..d46f386252 100644 --- a/synthesizer/process/src/finalize.rs +++ b/synthesizer/process/src/finalize.rs @@ -104,10 +104,10 @@ impl Process { lap!(timer, "Verify the number of transitions"); // Construct the call graph. - let call_graph = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { - Default::default() - } else { - self.construct_call_graph(execution)? + // If the height is greater than or equal to `CONSENSUS_V3_HEIGHT`, then provide an empty call graph, as it is no longer used during finalization. + let call_graph = match state.block_height() < N::CONSENSUS_V3_HEIGHT { + true => self.construct_call_graph(execution)?, + false => HashMap::new(), }; atomic_batch_scope!(store, { @@ -164,10 +164,10 @@ fn finalize_fee_transition>( fee: &Fee, ) -> Result>> { // Construct the call graph. - let call_graph = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { - Default::default() - } else { - HashMap::from([(*fee.transition_id(), Vec::new())]) + // If the height is greater than or equal to `CONSENSUS_V3_HEIGHT`, then provide an empty call graph, as it is no longer used during finalization. + let call_graph = match state.block_height() < N::CONSENSUS_V3_HEIGHT { + true => HashMap::from([(*fee.transition_id(), Vec::new())]), + false => HashMap::new(), }; // Finalize the transition. @@ -215,6 +215,7 @@ fn finalize_transition>( let mut states = Vec::new(); // Initialize a nonce for the finalize registers. + // Note that this nonce must be unique for each sub-transition being finalized. let mut nonce = 0; // Initialize the top-level finalize state. @@ -273,21 +274,22 @@ fn finalize_transition>( ); // Get the transition ID used to initialize the finalize registers. - // If the block height is greater than or equal to the consensus V3 height, return the main transition ID. + // If the block height is less than `CONSENSUS_V3_HEIGHT`, then use the top-level transition ID. // Otherwise, query the call graph for the child transition ID corresponding to the future that is being awaited. - let transition_id = if state.block_height() >= N::CONSENSUS_V3_HEIGHT { - *transition.id() - } else { - // Get the current transition ID. - let transition_id = registers.transition_id(); - // Get the child transition ID. - match call_graph.get(transition_id) { - Some(transitions) => match transitions.get(call_counter) { - Some(transition_id) => *transition_id, - None => bail!("Child transition ID not found."), - }, - None => bail!("Transition ID '{transition_id}' not found in call graph"), + let transition_id = match state.block_height() < N::CONSENSUS_V3_HEIGHT { + true => { + // Get the current transition ID. + let transition_id = registers.transition_id(); + // Get the child transition ID. + match call_graph.get(transition_id) { + Some(transitions) => match transitions.get(call_counter) { + Some(transition_id) => *transition_id, + None => bail!("Child transition ID not found."), + }, + None => bail!("Transition ID '{transition_id}' not found in call graph"), + } } + false => *transition.id(), }; // Increment the nonce. diff --git a/synthesizer/program/src/logic/command/rand_chacha.rs b/synthesizer/program/src/logic/command/rand_chacha.rs index f5e4fa7292..3bd3c3a0fa 100644 --- a/synthesizer/program/src/logic/command/rand_chacha.rs +++ b/synthesizer/program/src/logic/command/rand_chacha.rs @@ -89,27 +89,28 @@ impl RandChaCha { let seeds: Vec<_> = self.operands.iter().map(|operand| registers.load(stack, operand)).try_collect()?; // Construct the random seed. - let preimage = if registers.state().block_height() >= N::CONSENSUS_V3_HEIGHT { - to_bits_le![ + // If the height is greater than or equal to `CONSENSUS_V3_HEIGHT`, then use the new preimage definition. + // The difference is that a nonce is also included in the new definition. + let preimage = match registers.state().block_height() < N::CONSENSUS_V3_HEIGHT { + true => to_bits_le![ registers.state().random_seed(), **registers.transition_id(), stack.program_id(), registers.function_name(), - registers.nonce(), self.destination.locator(), self.destination_type.type_id(), seeds - ] - } else { - to_bits_le![ + ], + false => to_bits_le![ registers.state().random_seed(), **registers.transition_id(), stack.program_id(), registers.function_name(), + registers.nonce(), self.destination.locator(), self.destination_type.type_id(), seeds - ] + ], }; // Hash the preimage.