Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Falcon verification to use horner_eval_base #1661

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

Al-Kindi-0
Copy link
Collaborator

As the title says. The current cycle count is around 57500 cycles.

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

LGTM! Great job 👏

Left a few nits

#[test]
fn test_falcon512_probabilistic_product_failure() {
// Create a polynomial pi that is not equal to h * s2.
// create a polynomial pi that is not equal to h * s2.
Copy link
Contributor

Choose a reason for hiding this comment

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

The random_coefficients use rng - can we either fix a seed, or generate those coefficients deterministically?

Comment on lines 179 to 186
adv_push.2
dup.1 dup.1 ext2inv
push.0.0
loc_storew.4
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we add the state of the stack after this block?

@@ -218,182 +207,83 @@ export.load_h_s2_and_product.4
push.M u32lt assert
push.M u32lt assert

horner_eval_base
Copy link
Contributor

Choose a reason for hiding this comment

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

can we also add some comments for the state of the stack in this loop? It's quite hard to follow

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

I ran the miden-base tests on top of this branch, and I'm getting some NotU32 errors (for example, with the scripts::p2id::prove_consume_multiple_notes test).

Would be good to make sure the bus works fine too after we fix those (and #1664 might be useful if there's a bug there)

Copy link
Contributor

@plafer plafer left a comment

Choose a reason for hiding this comment

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

My bad, miden-base reimplements the dsa::falcon_sign method which was updated in this PR. After updating it, all tests pass.

I also confirmed that the bus is fixed with this PR, which confirms the findings of #1664 that rcombbase was the problem.

@Al-Kindi-0 Al-Kindi-0 force-pushed the al-introduce-horner-eval-ops branch from cec1812 to 6fcd075 Compare February 24, 2025 08:27
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few comments inline - most are pretty small.

padw

# For mem_stream
# 5) Load s2 and evaluate at tau_inv (Due to the final norm test we do not need to range check the s2 coefficients)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we explain somewhere in more detail why doing the final norm testing means no meed to range-check s2 coefficients?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I spent some time investigating this and it seems that the argument justifying this comment no longer holds. I think this is a result of the recent changes or maybe even earlier.
Looking at the norm_sq procedure too, we are doing there a u32lt which would have undefined behavior if the input is not already checked to be a u32, so we should at least have a u32 check on the coefficients of s2.
I have now added bound checks on the coefficients of s2 similar to those on h.
This has unfortunately led to an increase in the number of cycles, the current cycle count is just shy of 60000 cycles. We can comeback to this to see if we can optimize these checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense! Yeah - let's create an issue to figure out if we can do this range checking more efficiently somehow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created one here #1672

@bobbinth
Copy link
Contributor

One other thing, before merging this PR we'd need to update miden-base to make sure the advice state value generation for the Falcon signature works similar to what we have here now, right?

@Al-Kindi-0 Al-Kindi-0 force-pushed the al-introduce-horner-eval-ops branch from 6fcd075 to 3402f34 Compare February 24, 2025 08:44
Base automatically changed from al-introduce-horner-eval-ops to next February 24, 2025 08:58
@Al-Kindi-0
Copy link
Collaborator Author

One other thing, before merging this PR we'd need to update miden-base to make sure the advice state value generation for the Falcon signature works similar to what we have here now, right?

Indeed, we have now changed how and what advice is provided for the signature.

@Al-Kindi-0 Al-Kindi-0 force-pushed the al-update-falcon-with-horner branch 2 times, most recently from 66cfab3 to 4c3f3a4 Compare February 24, 2025 14:16
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left some more comments inline - these are mostly doc-related.

Also, would you mind making a parallel PR in miden-base?

@@ -8,11 +10,13 @@ use crate::ExecutionError;
/// vector of values to be pushed onto the advice stack.
/// The values are the ones required for a Falcon signature verification inside the VM and they are:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's add a newline above this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 17 to 15
/// 4. The challenge point at which we evaluate the three aforementioned polynomials to check the
/// product relationship.
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't the challenge point come first? I think we should lay this out the way it is laid out in the returned vector (and probably make this explicit in the comments). This way, we'll know that the first 2 elements of the returned vector are the challenge point, the next 512 are the $h$ polynomial etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, changed it now

Comment on lines 155 to 156
# 2. 4..8 the inverse of the evaluation point tau as [tau_inv0, tau_inv1, 0, 0],
# 3. 8..12 the evaluation point tau as [tau0, tau1, 0, 0],
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not store them next to each other - e.g., as [tau_inv0, tau_inv1, tau0, tau1]? Or does this create complications somehow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is mentally easier to store them in separate words but no other reason than that.
Changed it now to store both in the same word as well as updated the code to take that into account.

exec.load_h_s2_and_product
#=> [tau1, tau0, tau_ptr, MSG, NONCE1, NONCE1, ...] (Cycles: 5050)
#=> [MSG, ...] (Cycles: 6780)
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: why does this say "6780" cycles while cycle count for load_h_s2_and_product procedure says "4430"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Forgot to update the cycle count there. Updated now

Comment on lines +594 to +596
#! - h_i are the coefficients of the expanded public key polynomial.
#! - s2_i are the coefficients of the signature polynomial.
#! - pi_i are the coefficients of `h * s2` in Z_Q[x] where Q is the Miden VM prime.
#! - nonce_i are field elements representing the nonce associated to the signature.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also describe what "tau" is here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added a short description

## a) Set up the accumulator for `horner_eval_base` and the memory pointers
push.0.0
locaddr.4
movup.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add stack state after this instruction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

adv_push.2
dup.1 dup.1 ext2inv
push.0.0
loc_storew.4
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add stack state after this instruction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

u32overflowing_sub.M assert drop
u32overflowing_sub.M assert drop

horner_eval_base

hperm
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add stack state after this loop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done


## a) Reset the accumulator, update the pointers and set up the state of the hasher
push.0 movdn.6
push.0 movdn.6
padw padw
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add stack state after this instruction?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@Al-Kindi-0
Copy link
Collaborator Author

Also, would you mind making a parallel PR in miden-base?

Sure thing, will open one soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants