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

Add faster STARK configuration for testing purposes #739

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

sai-deng
Copy link
Contributor

@sai-deng sai-deng commented Oct 21, 2024

#676 Enables fast STARK configurations in integration tests. Achieved up to 82% test time savings. Detailed results are provided below.
Next, I will work on enabling it in Zero Bin.

Test Name Old TIme (sec) New TIme (sec) Time Savings
add11_yml 4.85 3.56 26.60%
empty_table 39.54 7.1 82.04%
erc20 4.93 3.58 27.38%
erc721 18.14 13.59 25.08%
log_opcodes 6.07 4.56 24.88%
selfdestruct 4.81 3.49 27.44%
simple_transfer 4.79 3.43 28.39%
two_to_one_block_aggregation 176.52 38.00 78.47%
withdrawals 3.8 2.97 21.84%

With the big test time savings for the two_to_one_block_aggregation test, I have removed [ignore] from it.

@github-actions github-actions bot added the crate: evm_arithmetization Anything related to the evm_arithmetization crate. label Oct 21, 2024
@github-actions github-actions bot added the crate: zero_bin Anything related to the zero-bin subcrates. label Oct 22, 2024
@sai-deng sai-deng marked this pull request as ready for review October 22, 2024 02:48
@sai-deng sai-deng self-assigned this Oct 23, 2024
// When using test configurations, the block circuit's degree is less than the
// 2-to-1 circuit's degree. Therefore, we also need to ensure its size meets
// the 2-to-1 circuit's recursion threshold degree bits.
while log2_ceil(builder.num_gates()) < TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS {
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we want to test another circuit that doesn't require the same number of degree bits? I don't think TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS should be constant, because even though now, we're only using this to test the 2-to-1 circuit in the CI, we should still be able to use this for other circuits that might not have the same size...

Also, I'm actually surprised TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS is greater than common.degree_bits(). Do you know why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS is the smallest degree bits we can get with a low-security STARK config for the 2-1-block circuit. We will not use this value for other circuits.

We need it in the block wrapper circuit because we need to match its degree with the 2-1-block circuit’s degree, but we build this circuit before the 2-1-block circuit so we need to know this value in advance.

Copy link
Contributor

Choose a reason for hiding this comment

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

But why does the common circuit data not contain a high enough degree then? Shouldn't the common data and the circuit we're building agree on the degree_bits?
Also, if we keep this, maybe we should have something like:
while log2_ceil(builder.num_gates()) < max(TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS, block.circuit.common.degree_bits())
to not have two different while loops doing the same thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous check log2_ceil(builder.num_gates()) < block.circuit.common.degree_bits() is a hack, as described in the comments.

The degree_bits is needed for this circuit is determined in the next layer of recursion, while the common data is from the last layer of recursion. Therefore, they may not align. We could use a trial-and-error loop to find this number, but it would be much slower and seems excessive for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve completed the refactoring to keep only one while. PTAL


let all_circuits = AllRecursiveCircuits::new(
&all_stark,
&[16..17, 8..9, 12..13, 8..9, 8..9, 6..7, 17..18, 16..17, 7..8],
&config,
Some(&TEST_RECURSION_CONFIG),
Some(&TEST_RECURSION_CONFIG),
None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't it TWO_TO_ONE_BLOCK_CIRCUIT_TEST_THRESHOLD_DEGREE_BITS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only for 2-to-1 block circuit's threshold.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should use TEST_THRESHOLD_DEGREE_BITS. Thanks for the catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, we have two_to_one_block aggregation test passing in 38 seconds on my MacBook. We can confidently remove [ignored] from it now.

Copy link
Contributor

@LindaGuiga LindaGuiga left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate: evm_arithmetization Anything related to the evm_arithmetization crate. crate: zero_bin Anything related to the zero-bin subcrates.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants