Skip to content

Conversation

@xqft
Copy link
Contributor

@xqft xqft commented Dec 5, 2025

Motivation

Execution with SP1 was failing after PR #5529 which changes a line of the ecmul precompile to make it compatible with an API difference between the substrate-bn patch of SP1 and ZisK.

Apparently this also changes the behavior of the multiplication for the SP1 patch, and some blocks (like block 23919500 from Mainnet) were failing to execute due to a gas mismatch error.

Reverting the change for SP1 fixes the issue.

Copilot AI review requested due to automatic review settings December 5, 2025 21:10
@xqft xqft requested a review from a team as a code owner December 5, 2025 21:10
@github-actions github-actions bot added the L2 Rollup client label Dec 5, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a gas mismatch error when executing blocks with SP1 by conditionally handling the type conversion in the bn254_g1_mul precompile. The issue was introduced by PR #5529, which unified the behavior across SP1 and ZisK but inadvertently changed SP1's multiplication semantics.

Key Changes:

  • Modified the bn254_g1_mul function to only convert AffineG1 to G1 when the zisk feature is enabled
  • For SP1, the point remains as AffineG1 during scalar multiplication to preserve correct gas calculation behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

let g1 = AffineG1::new(g1_x, g1_y)
.map_err(|_| PrecompileError::InvalidPoint)?;

// Small difference between the patched versions of substrate-bn
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The comment should explain WHY this conditional conversion is needed and what the actual difference is between the SP1 and ZisK substrate-bn patches. Consider expanding it to something like:

// SP1's substrate-bn patch implements multiplication for AffineG1 * Fr differently
// than ZisK's patch. For ZisK, we need to convert to G1 first, while SP1 requires
// AffineG1 to avoid gas mismatch issues (e.g., block 23919500 from Mainnet).

This would help future maintainers understand the reasoning behind this platform-specific behavior.

Suggested change
// Small difference between the patched versions of substrate-bn
// SP1's substrate-bn patch implements multiplication for AffineG1 * Fr differently
// than ZisK's patch. For ZisK, we need to convert to G1 first, while SP1 requires
// AffineG1 to avoid gas mismatch issues (e.g., block 23919500 from Mainnet).

Copilot uses AI. Check for mistakes.
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Lines of code report

Total lines added: 1
Total lines removed: 0
Total lines changed: 1

Detailed view
+------------------------------------------+-------+------+
| File                                     | Lines | Diff |
+------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs | 1667  | +1   |
+------------------------------------------+-------+------+

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Benchmark Results Comparison

No significant difference was registered for any benchmark run.

Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 2.824 ± 0.010 2.812 2.849 1.00
main_levm_BubbleSort 2.987 ± 0.028 2.970 3.059 1.06 ± 0.01
pr_revm_BubbleSort 2.828 ± 0.022 2.815 2.873 1.00 ± 0.01
pr_levm_BubbleSort 2.976 ± 0.016 2.964 3.017 1.05 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Approval 904.7 ± 11.8 896.0 927.7 1.00 ± 0.02
main_levm_ERC20Approval 1050.4 ± 8.4 1042.1 1067.8 1.16 ± 0.02
pr_revm_ERC20Approval 904.6 ± 10.8 894.1 921.6 1.00
pr_levm_ERC20Approval 1054.3 ± 17.5 1042.0 1088.4 1.17 ± 0.02

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 120.2 ± 1.5 119.1 124.2 1.01 ± 0.01
main_levm_ERC20Mint 151.9 ± 4.1 150.1 163.4 1.27 ± 0.03
pr_revm_ERC20Mint 119.4 ± 0.4 118.9 120.1 1.00
pr_levm_ERC20Mint 151.2 ± 0.8 150.1 152.9 1.27 ± 0.01

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 213.6 ± 3.4 211.4 221.6 1.00
main_levm_ERC20Transfer 265.2 ± 4.0 261.5 271.9 1.24 ± 0.03
pr_revm_ERC20Transfer 213.7 ± 4.9 211.1 227.5 1.00 ± 0.03
pr_levm_ERC20Transfer 262.6 ± 1.2 261.8 265.9 1.23 ± 0.02

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 185.8 ± 2.5 184.0 192.5 1.00 ± 0.01
main_levm_Factorial 223.3 ± 3.7 220.0 233.0 1.21 ± 0.02
pr_revm_Factorial 185.3 ± 1.0 184.4 187.0 1.00
pr_levm_Factorial 222.9 ± 2.7 220.2 229.5 1.20 ± 0.02

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.270 ± 0.049 1.136 1.307 1.00
main_levm_FactorialRecursive 6.137 ± 0.028 6.077 6.166 4.83 ± 0.19
pr_revm_FactorialRecursive 1.285 ± 0.046 1.170 1.337 1.01 ± 0.05
pr_levm_FactorialRecursive 6.150 ± 0.045 6.071 6.238 4.84 ± 0.19

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 154.1 ± 4.8 150.5 164.4 1.02 ± 0.03
main_levm_Fibonacci 205.6 ± 1.2 204.4 207.8 1.35 ± 0.01
pr_revm_Fibonacci 151.8 ± 1.3 150.4 154.7 1.00
pr_levm_Fibonacci 208.5 ± 7.9 204.5 230.2 1.37 ± 0.05

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 696.0 ± 4.0 690.2 701.7 1.08 ± 0.01
main_levm_FibonacciRecursive 644.3 ± 5.5 639.8 658.6 1.00 ± 0.01
pr_revm_FibonacciRecursive 697.8 ± 4.7 691.7 706.5 1.09 ± 0.01
pr_levm_FibonacciRecursive 642.6 ± 3.0 637.9 646.2 1.00

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 7.8 ± 0.2 7.6 8.3 1.02 ± 0.03
main_levm_ManyHashes 8.7 ± 0.3 8.5 9.5 1.13 ± 0.04
pr_revm_ManyHashes 7.7 ± 0.1 7.6 7.8 1.00
pr_levm_ManyHashes 8.6 ± 0.2 8.5 9.0 1.12 ± 0.02

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 255.1 ± 1.5 252.9 258.2 1.14 ± 0.03
main_levm_MstoreBench 227.2 ± 9.6 221.4 251.5 1.02 ± 0.05
pr_revm_MstoreBench 254.7 ± 0.5 253.8 255.5 1.14 ± 0.03
pr_levm_MstoreBench 223.2 ± 4.9 219.6 236.4 1.00

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 240.0 ± 0.5 239.6 241.2 1.00
main_levm_Push 255.6 ± 10.9 250.3 286.2 1.06 ± 0.05
pr_revm_Push 240.6 ± 2.1 239.3 246.3 1.00 ± 0.01
pr_levm_Push 254.1 ± 5.3 250.0 266.5 1.06 ± 0.02

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 146.7 ± 8.8 142.1 169.3 1.92 ± 0.12
main_levm_SstoreBench_no_opt 77.6 ± 2.3 75.7 82.7 1.01 ± 0.03
pr_revm_SstoreBench_no_opt 144.1 ± 3.5 141.7 153.7 1.88 ± 0.05
pr_levm_SstoreBench_no_opt 76.6 ± 1.0 75.5 78.5 1.00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants