feat(vm): add P256VERIFY precompile (TIP-7951)#6720
Open
yanghang8612 wants to merge 2 commits intotronprotocol:developfrom
Open
feat(vm): add P256VERIFY precompile (TIP-7951)#6720yanghang8612 wants to merge 2 commits intotronprotocol:developfrom
yanghang8612 wants to merge 2 commits intotronprotocol:developfrom
Conversation
Pure-Java BC port of EIP-7951; gated by ALLOW_TVM_OSAKA.
Manual @test, not part of regular suite. Run via --tests filter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
0x100, gated byALLOW_TVM_OSAKA.P256VerifyTest).PrecompileBenchmark) compare against ECRecover. TEST 4 (coldNoWarmup) measures cold no-warmup latency to reflect the low-frequency mainnet case where the JVM has not JIT-compiled the precompile path.Spec
Test
./gradlew :framework:test --tests org.tron.common.runtime.vm.P256VerifyTest./gradlew :framework:test --tests org.tron.common.runtime.vm.AllowTvmOsakaTest./gradlew :framework:test --no-daemon --tests 'org.tron.common.runtime.vm.PrecompileBenchmark.coldNoWarmup' -i./gradlew :framework:test --no-daemon --tests 'org.tron.common.runtime.vm.PrecompileBenchmark' -iBenchmark
Server: Linux 8 cores / 32 GB. Two separate
--no-daemonruns so the cold measurement gets a truly cold JVM:--tests 'PrecompileBenchmark.coldNoWarmup'--tests 'PrecompileBenchmark'(provides warm steady-state and fail-path numbers)Warm steady-state — TEST 1 / TEST 3 (5000-iter warmup, 5000 × 5 measure)
At C2 steady state P256 is ~1.75× slower than ECRecover — well under the 2.30× gas ratio (6900/3000), so the proposed pricing carries ~24% safety margin.
Cold no-warmup — TEST 4 (100 distinct inputs, per-call timing)
The first call pays full JIT / classloading / minor-GC tax — both precompiles land in the 10–20 ms range. P256VERIFY's first call is actually lower than ECRecover's because BouncyCastle's secp256k1 path has more cold code to load. After 100 invocations the JVM has not yet triggered C1/C2 (
-XX:CompileThreshold=10000default), so per-call cost stays around 2 ms — three orders of magnitude above the C2 steady state of ~2 µs. This is the realistic upper bound for a low-frequency precompile that rarely reaches JIT steady state.Fail-path early-exit — TEST 2 (warm, 5000-iter warmup, 5000 × 5 measure)
len != 160r ≥ N(modulus bound)qx ≥ P(field bound)Confirms the cheap guards short-circuit before scalar multiplication: length / bound / infinity checks finish in ~100–500 ns, three orders of magnitude faster than a full ECDSA pass. Off-curve detection costs one curve-equation evaluation (~2 µs) but is still ~1000× cheaper than a full verify. A failing ECDSA verify costs the same as a passing one — both run the full scalar multiplication; only the final equality check differs.