Skip to content

Commit

Permalink
Merge pull request #2579 from ProvableHQ/cache_to_address
Browse files Browse the repository at this point in the history
[Perf] Cache program address in Stack
  • Loading branch information
zosorock authored Dec 10, 2024
2 parents 4965f6b + e37b7f7 commit b0c901d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions synthesizer/process/src/stack/helpers/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl<N: Network> Stack<N> {
number_of_calls: Default::default(),
finalize_costs: Default::default(),
program_depth: 0,
program_address: program.id().to_address()?,
};

// Add all the imports into the stack.
Expand Down
8 changes: 8 additions & 0 deletions synthesizer/process/src/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ pub struct Stack<N: Network> {
finalize_costs: IndexMap<Identifier<N>, u64>,
/// The program depth.
program_depth: usize,
/// The program address.
program_address: Address<N>,
}

impl<N: Network> Stack<N> {
Expand Down Expand Up @@ -240,6 +242,12 @@ impl<N: Network> StackProgram<N> for Stack<N> {
self.program_depth
}

/// Returns the program address.
#[inline]
fn program_address(&self) -> &Address<N> {
&self.program_address
}

/// Returns `true` if the stack contains the external record.
#[inline]
fn contains_external_record(&self, locator: &Locator<N>) -> bool {
Expand Down
6 changes: 5 additions & 1 deletion synthesizer/process/src/verify_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ impl<N: Network> Process<N> {
// If there is no parent, then `is_root` is `1` and `parent` is the root program ID.
None => (Field::one(), *transition.program_id()),
};

// Retrieve the adress belonging to the parent.
let parent_address = self.get_stack(parent)?.program_address();

// Compute the x- and y-coordinate of `parent`.
let (parent_x, parent_y) = parent.to_address()?.to_xy_coordinates();
let (parent_x, parent_y) = parent_address.to_xy_coordinates();

// [Inputs] Construct the verifier inputs to verify the proof.
let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **transition.tcm(), **transition.scm()];
Expand Down
10 changes: 8 additions & 2 deletions synthesizer/process/src/verify_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ impl<N: Network> Process<N> {
// Compute the x- and y-coordinate of `tpk`.
let (tpk_x, tpk_y) = fee.tpk().to_xy_coordinates();

// Retrieve the adress belonging to the program ID.
let program_adress = self.get_stack(fee.program_id())?.program_address();

// Compute the x- and y-coordinate of `parent`.
let (parent_x, parent_y) = fee.program_id().to_address()?.to_xy_coordinates();
let (parent_x, parent_y) = program_adress.to_xy_coordinates();

// Construct the public inputs to verify the proof.
let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm(), **fee.scm()];
Expand Down Expand Up @@ -194,8 +197,11 @@ impl<N: Network> Process<N> {
// Compute the x- and y-coordinate of `tpk`.
let (tpk_x, tpk_y) = fee.tpk().to_xy_coordinates();

// Retrieve the adress belonging to the program ID.
let program_adress = self.get_stack(fee.program_id())?.program_address();

// Compute the x- and y-coordinate of `parent`.
let (parent_x, parent_y) = fee.program_id().to_address()?.to_xy_coordinates();
let (parent_x, parent_y) = program_adress.to_xy_coordinates();

// Construct the public inputs to verify the proof.
let mut inputs = vec![N::Field::one(), *tpk_x, *tpk_y, **fee.tcm(), **fee.scm()];
Expand Down
3 changes: 3 additions & 0 deletions synthesizer/program/src/traits/stack_and_registers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ pub trait StackProgram<N: Network> {
/// Returns the program depth.
fn program_depth(&self) -> usize;

/// Returns the program address.
fn program_address(&self) -> &Address<N>;

/// Returns `true` if the stack contains the external record.
fn contains_external_record(&self, locator: &Locator<N>) -> bool;

Expand Down

0 comments on commit b0c901d

Please sign in to comment.