feat: PVM update 0.8.0 - #1046
Open
TwEricShen wants to merge 1 commit into
Open
Conversation
Closed
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.
Part of #1022
Summary
Aligns the PVM implementation with Gray Paper v0.8.0 Appendix A & B, including:
gaschargedflag, A.9 ROB gas model, A.10 opcode cost tables,unlikely, branch/jump dual-target validation,deblob/𝔳_instfirst-run validation,IntegratedPVMType, etc.grow_heapinserted at ID=1), per-function linear gas (Appendix H constants),invokegas refund,machine63-slot cap,bless/designate/querysemantic updates.The interpreter and recompiler share the same gas engine (
GasCostForBlock/GasCostFromPC/blockGasAtPC). The recompiler bakes block gas at compile time (emitBlockGasCheck).Submodule: gas model test vectors
New submodule:
pkg/test_data/new-gas-cost-modelhttps://github.com/koute/new-gas-cost-model.gitgascostforblockvectors (aligned with koute / w3f/jamtestvectors PR #3)Required for reviewers / CI (gas tests fail immediately if the vectors directory is missing):
git submodule update --init --recursive pkg/test_data/new-gas-cost-model # or all submodules git submodule update --init --recursiveVerify the submodule points at the expected commit:
Main changes (PVM)
gas_sim.go,gas_opcode.go,gas_regs.go,gas_model.gogascostforblock = max(cycles−3, 1)invocation.go,block_info.goGasChargedflag,blockGasAtPCcachegas_const.go,host_call_*.goMemGaslinear billingrecompiler/gas.go,compiler.goemitBlockGasCheckhost_call_refine.go,host_call_invoke_test.goBlockBasedInvokeDecodedBlocks, suffix gas,gasChargedForIntegratedResumeinstructions*.go,program_code.gounlikely, branch dual-target, sjump,DeBlobProgramCode(blob, pc)host_call_general.go, recompiler emitexecution_backend.go,interpreter/,recompiler/PVM.WithExecutionBackend/SetExecutionBackendcmd/pvmtrace/deblob_program.go,scripts/scan_psi_a_program_blobs.pyImplementation choice (not spelled out in GP)
Mid-block resume gas: when entry PC is mid-block and
gaschargedflag=⊥, charge suffixGasCostFromPC(ι)(not the full containing block). Matches koute gas vectors and recompiler suffix compilation.Tests
Gas model (koute vectors) — expected all PASS
Data root:
pkg/test_data/new-gas-cost-model/TestGasModelProgramVectorstests/programs/gas_*.jsongo test ./PVM/ -run TestGasModelProgramVectors -count=1TestGasModelInstVectorstests/programs/inst_*.jsongo test ./PVM/ -run TestGasModelInstVectors -count=1TestGasModelRiscvVectorstests/programs/riscv_*.jsongo test ./PVM/ -run TestGasModelRiscvVectors -count=1TestGasModelMultistepVectorstests/programs/multistep_*.jsongo test ./PVM/ -run TestGasModelMultistepVectors -count=1TestGasModelIntegrationVectorsintegration-tests/*.jsongo test ./PVM/ -run TestGasModelIntegrationVectors -count=1TestGasVectorHarnessSanitygas_*.jsongo test ./PVM/ -run TestGasVectorHarnessSanity -count=1Total: 362 program vectors + 3 integration = 365 JSON files in the tree.
Run all gas-related tests:
Each vector asserts
GasCostForBlock(prog, pc)equals the JSONblock-gas-costsentry.Gas model unit tests (non-vector)
TestBlockGasFromCyclesmax(cycles−3, 1)formulago test ./PVM/ -run TestBlockGasFromCycles -count=1TestGasCostSingleTrapBlockgo test ./PVM/ -run TestGasCostSingleTrapBlock -count=1TestGasCostMoveRegBlockmove_regbypasses ROBgo test ./PVM/ -run TestGasCostMoveRegBlock -count=1TestGasCostBranchToTrapgo test ./PVM/ -run TestGasCostBranchToTrap -count=1TestInstructionCostEcalli/TestInstRegsEcalliInvocation / block gas behavior
TestBlockBasedInvokeDecodedBlocksChargesContainingBlockgo test ./PVM/ -run TestBlockBasedInvokeDecodedBlocks -count=1TestBlockBasedInvokeDecodedBlocksResumesAfterHostCallTestBlockBasedInvoke*/TestDebugSingleStepInvoke*TestBlockGasAtPCUsesCacheAtBlockEntrygo test ./PVM/ -run TestBlockGasAtPCUsesCacheAtBlockEntry -count=1TestGasChargedForIntegratedResume/TestInvokeInnerTrapDeductsBlockGasHost-call gas / v0.8 semantics
TestAddGasAndUnitGasCostMemGas/ unit gasgo test ./PVM/ -run TestAddGasAndUnitGasCost -count=1TestPagesGasCostpagestiered gasgo test ./PVM/ -run TestPagesGasCost -count=1TestLookupLinearGasOOGgo test ./PVM/ -run TestLookupLinearGasOOG -count=1TestQueryBlobLengthHUH/TestBlessManagerOnlyTestFetchCostfetchtiered gasgo test ./PVM/ -run TestFetchCost -count=1Recompiler (linux/amd64 + CGO)
TestCompileAllOpcodesCGO_ENABLED=1 go test ./PVM/recompiler/ -run TestCompileAllOpcodes -count=1TestExecuteInstructionsCGO_ENABLED=1 go test ./PVM/recompiler/ -run TestExecuteInstructions -count=1TestBlockEntryOOGLeavesGasUnchangedCGO_ENABLED=1 go test ./PVM/recompiler/ -run TestBlockEntryOOG -count=1TestBlockGasChargedAcrossHostCallGasChargedflag across host callCGO_ENABLED=1 go test ./PVM/recompiler/ -run TestBlockGasChargedAcrossHostCall -count=1TestSuffixBlockGasMatchesGasCostFromPCCGO_ENABLED=1 go test ./PVM/recompiler/ -run TestSuffixBlockGasMatchesGasCostFromPC -count=1make run-recompiler-testInterpreter ↔ Recompiler consistency — currently FAIL (known)
TestInterpreterVsRecompilerProgramBlobsΨ_M(Accumulate) on interpreter vs recompiler; requires matching Gas + ReasonOrBytesPVM/testdata/psi_a_consistency/blobs/*.bin(30 blobs)scripts/scan_psi_a_program_blobs.pyscans large keyvals (MetaCode preimages) frompkg/test_data/jam-conformance/fuzz-reports/0.7.2/traces/linux && amd64 && cgomake test-backend-consistencyorCGO_ENABLED=1 go test -count=1 -timeout 30m -v ./PVM/ -run TestInterpreterVsRecompilerProgramBlobsgrow_heapinserted, etc.) — not an interpreter/recompiler divergenceExample blob scan:
Suggested reviewer verification order
git submodule update --init --recursive pkg/test_data/new-gas-cost-modelgo test ./PVM/ -run 'TestGasModel|TestGasVectorHarnessSanity' -count=1go test ./PVM/ -count=1 -skip TestInterpreterVsRecompilerProgramBlobsCGO_ENABLED=1 go test ./PVM/recompiler/... -count=1(linux/amd64)Related