Skip to content

Commit

Permalink
feat: optimize computation of DEEP queries
Browse files Browse the repository at this point in the history
chore: update changelog
  • Loading branch information
Al-Kindi-0 committed Dec 7, 2024
1 parent b7ff6c8 commit bec35e8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 50 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#### Enhancements
- Added `miden_core::mast::MastForest::advice_map` to load it into the advice provider before the `MastForest` execution (#1574).
- Optimized the computation of the DEEP queries in the recursive verifier (#1594).

## 0.11.0 (2024-11-04)

Expand Down
6 changes: 6 additions & 0 deletions stdlib/asm/crypto/stark/constants.masm
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const.TMP5=4294903319
const.TMP6=4294903320
const.TMP7=4294903321
const.TMP8=4294903322
const.TMP9=4294903323



Expand Down Expand Up @@ -135,6 +136,7 @@ const.TMP8=4294903322
# | TMP6 | 4294903320 |
# | TMP7 | 4294903321 |
# | TMP8 | 4294903322 |
# | TMP9 | 4294903323 |
# +------------------------------------------+-------------------------+

# ACCESSORS
Expand Down Expand Up @@ -305,3 +307,7 @@ end
export.tmp8
push.TMP8
end

export.tmp9
push.TMP9
end
104 changes: 57 additions & 47 deletions stdlib/asm/crypto/stark/deep_queries.masm
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,20 @@ end
#! Loads the next query rows in the main, auxiliary and constraint composition polynomials traces.
#! It takes a pointer to the current random query index and returns that index.
#!
#! Input: [query_ptr, ...]
#! Input: [X, query_ptr, ...]
#! Output: [index, query_ptr, ...]
#!
#! Cycles: 219
#! Cycles: 206
proc.load_query_row
# Main trace portion of the query

## Get the next query index
padw
dup.4
mem_loadw
swap
#=> [depth, index, y, y, query_ptr, ...]
#=> [index, depth, y, y, query_ptr, ...]

## Get main trace commitment and use it to get the leaf
movup.3 movup.3
movdn.3 movdn.2
push.0.0
exec.constants::main_trace_com_ptr mem_loadw
#=>[R, depth, index, query_ptr, ...]
Expand Down Expand Up @@ -273,50 +271,44 @@ proc.load_query_row
assert_eq
#=> [Y, ptr, y, y, y, depth, index, query_ptr, ...]

dropw dropw drop
#=> [index, query_ptr, ...]
drop
#=> [Y, Y, index, query_ptr, ...]
end

#! Takes a query index and computes x := offset * domain_gen^index. It also computes the denominators
#! (x - z) and (x - gz).
#!
#! Input: [index, ...]
#! Output: [Z, x, index, ...] where Z := [-gz1, x -gz0, -z1, x - z0]
#! Input: [Y, Y, index, ...]
#! Output: [Z, Y, x, index, ...] where Z := [-gz1, x -gz0, -z1, x - z0] and Y are "garbage" values.
#!
#! Cycles: 68
#! Cycles: 58
proc.compute_denominators
# Compute x = offset * domain_gen^index
padw
exec.constants::lde_size_ptr mem_loadw
#=> [lde_size, depth, domain_gen, 0, index, ...]
#=> [lde_size, depth, domain_gen, 0, Y, index, ...]
movup.2
dup.4
dup.8
exp.u32
exec.constants::domain_offset mul
#=> [x, lde_size, depth, 0, index, ...]
#=> [x, lde_size, depth, 0, Y, index, ...]

# Get z and gz from memory
movdn.3
#=> [lde_size, depth, 0, x, index, ...]
#=> [lde_size, depth, 0, x, Y, index, ...]
push.0
exec.constants::tmp1 mem_loadw
#=> [gz1, gz0, z1, z0, x, index, ...]
#=> [-z0, -gz0, -gz1, -z1, x, Y, index, ...]

# Compute Z := [-z1, x - z0, -gz1, x -gz0]
neg
dup.4
movup.2
sub
#=> [x-gz0, -gz1, z1, z0, x, index, ...]
movdn.3
movdn.2
#=> [z1, z0, -gz1, x-gz0, x, index, ...]
neg
dup.4 add
#=> [x-z0, -gz0, -gz1, -z1, x, Y, index, ...]
movdn.3
dup.4 swap
sub
movdn.3
#=> [Z, x, index, ...] where Z := [-gz1, x -gz0, -z1, x - z0]
#=> [-gz0, -gz1, -z1, x-z0, x, Y, index, ...]

movup.4 dup movdn.9
#=> [x, -gz0, -gz1, -z1, x-z0, Y, x, index, ...]

add swap
#=> [-gz1, x - gz0, -z1, x-z0, Y, x, index, ...]
end

#! Computes the random linear combination involving the main trace columns and accumulates
Expand Down Expand Up @@ -467,11 +459,34 @@ end
#!
#! Input: [query_ptr, ...]
#! Output: [...]
#! Cycles: 6 + num_queries * 473
#! Cycles: 24 + num_queries * 445
export.compute_deep_composition_polynomial_queries

exec.constants::fri_com_ptr
dup.1
#=>[query_ptr, query_end_ptr, ...]
push.0
exec.constants::deep_rand_coef_ptr
exec.constants::ood_trace_ptr
exec.constants::current_trace_row_ptr
exec.constants::tmp9 mem_storew
#=>[X, query_ptr, query_end_ptr, ...]

# Compute the negations of z and gz.
# We do it here as this computation is common to all queries.
exec.constants::z_ptr mem_loadw
drop drop
neg swap neg
#=> [-z0, -z1, ...]
dup.1 exec.constants::trace_domain_generator_ptr mem_load mul
#=> [-gz1, -z0, -z1, ...]
swap
#=> [-z0, -gz1, -z1, ...]
dup exec.constants::trace_domain_generator_ptr mem_load mul
#=> [-gz0, -z0, -gz1, -z1, ...]
swap
#=> [-z0, -gz0, -gz1, -z1, ...]
exec.constants::tmp1 mem_storew
#=>[X, query_ptr, query_end_ptr, ...]

push.1
while.true
Expand All @@ -480,19 +495,18 @@ export.compute_deep_composition_polynomial_queries
# Load the (main, aux, constraint)-traces rows associated with the current query and get
# the index of the query.
#
# Cycles: 219
# Cycles: 206
exec.load_query_row
#=>[index, query_ptr, query_end_ptr, ...]
#=>[Y, Y, index, query_ptr, query_end_ptr, ...]


# II)
#
# Compute x := offset * domain_gen^index and denominators (x - z) and (x - gz)
#
# Cycles: 68
# Cycles: 58
exec.compute_denominators
#=> [Z, x, index, query_ptr, query_end_ptr, ...] where Z := [-gz1, x - gz0, -z1, x - z0]

#=> [Z, Y, x, index, query_ptr, query_end_ptr, ...] where Z := [-gz1, x - gz0, -z1, x - z0]

# III)
#
Expand All @@ -503,11 +517,8 @@ export.compute_deep_composition_polynomial_queries

## a) Push pointers
##
## Cycles: 4
push.0
exec.constants::deep_rand_coef_ptr
exec.constants::ood_trace_ptr
exec.constants::current_trace_row_ptr
## Cycles: 3
swapw exec.constants::tmp9 mem_loadw
#=> [P, Z, x, index, query_ptr, query_end_ptr, ...]
# where P := [CURRENT_TRACE_ROW_PTR, OOD_TRACE_PTR, DEEP_RAND_CC_PTR, 0]

Expand Down Expand Up @@ -560,11 +571,10 @@ export.compute_deep_composition_polynomial_queries

## c) Prepare stack for next iteration
##
## Cycles: 8
dropw
dup.1 dup.1
## Cycles: 4
dup.5 dup.5
neq
#=> [?, query_ptr+1, query_end_ptr, ...]
end
drop drop
dropw drop drop
end
6 changes: 3 additions & 3 deletions stdlib/asm/crypto/stark/verifier.masm
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use.std::crypto::stark::constants
#! Output: []
#! Cycles:
#! 1- Remainder codeword size 32:
#! 4975 + num_queries * (40 + num_fri_layers * 76 + 26 + 473) + 83 * num_fri_layers + 10 * log(trace_length) + 1633
#! 4985 + num_queries * (40 + num_fri_layers * 76 + 26 + 445) + 83 * num_fri_layers + 10 * log(trace_length) + 1633
#! 2- Remainder codeword size 64:
#! 4975 + num_queries * (40 + num_fri_layers * 76 + 26 + 473) + 83 * num_fri_layers + 10 * log(trace_length) + 3109
#! 4985 + num_queries * (40 + num_fri_layers * 76 + 26 + 445) + 83 * num_fri_layers + 10 * log(trace_length) + 3109
export.verify

#==============================================================================================
Expand Down Expand Up @@ -221,7 +221,7 @@ export.verify

# Compute deep compostion polynomial queries
#
# Cycles: 14 + num_queries * 473
# Cycles: 24 + num_queries * 445
#=> [query_ptr, ...]
exec.deep_queries::compute_deep_composition_polynomial_queries
#=> [query_ptr, ...]
Expand Down

0 comments on commit bec35e8

Please sign in to comment.