diff --git a/core/vm/contracts.go b/core/vm/contracts.go index c4c42fb5e6fe6..2f124b0b4e513 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -92,7 +92,7 @@ var PrecompiledContractsBerlin = map[common.Address]PrecompiledContract{ } // PrecompiledContractsCancun contains the default set of pre-compiled Ethereum -// contracts used in the Berlin release. +// contracts used in the Cancun release. var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{1}): &ecrecover{}, common.BytesToAddress([]byte{2}): &sha256hash{}, @@ -103,7 +103,7 @@ var PrecompiledContractsCancun = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{}, common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{}, common.BytesToAddress([]byte{9}): &blake2F{}, - common.BytesToAddress([]byte{20}): &pointEvaluation{}, + common.BytesToAddress([]byte{20}): &kzgPointEvaluation{}, } // PrecompiledContractsBLS contains the set of pre-compiled Ethereum @@ -1071,17 +1071,18 @@ func (c *bls12381MapG2) Run(input []byte) ([]byte, error) { return g.EncodePoint(r), nil } -// pointEvaluation implements the EIP-4844 point evaluation precompile. -type pointEvaluation struct{} +// kzgPointEvaluation implements the EIP-4844 point evaluation precompile. +type kzgPointEvaluation struct{} // RequiredGas estimates the gas required for running the point evaluation precompile. -func (b *pointEvaluation) RequiredGas(input []byte) uint64 { - return params.PointEvaluationPrecompileGas +func (b *kzgPointEvaluation) RequiredGas(input []byte) uint64 { + return params.BlobTxPointEvaluationPrecompileGas } const ( - pointBlobVerifyInputLength = 192 // Max input length for the point evaluation precompile. - blobVerifyKZGVersion uint8 = 0x01 // Version byte for the point evaluation precompile. + blobVerifyInputLength = 192 // Max input length for the point evaluation precompile. + blobVerifyKZGVersion uint8 = 0x01 // Version byte for the point evaluation precompile. + blobPrecompileReturnValue = "000000000000000000000000000000000000000000000000000000000000100073eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001" ) var ( @@ -1091,8 +1092,8 @@ var ( ) // Run executes the point evaluation precompile. -func (b *pointEvaluation) Run(input []byte) ([]byte, error) { - if len(input) != pointBlobVerifyInputLength { +func (b *kzgPointEvaluation) Run(input []byte) ([]byte, error) { + if len(input) != blobVerifyInputLength { return nil, errBlobVerifyInvalidInputLength } // versioned hash: first 32 bytes @@ -1117,13 +1118,13 @@ func (b *pointEvaluation) Run(input []byte) ([]byte, error) { // Proof: next 48 bytes var proof kzg4844.Proof - copy(proof[:], input[144:pointBlobVerifyInputLength]) + copy(proof[:], input[144:blobVerifyInputLength]) if err := kzg4844.VerifyProof(commitment, point, claim, proof); err != nil { return nil, errors.Join(errBlobVerifyKZGProof, err) } - return common.CopyBytes(kzg4844.PrecompileReturnValue[:]), nil + return common.Hex2Bytes(blobPrecompileReturnValue), nil } // KZGToVersionedHash implements kzg_to_versioned_hash from EIP-4844 diff --git a/core/vm/contracts_test.go b/core/vm/contracts_test.go index 36dcd4076064d..8223d61159c72 100644 --- a/core/vm/contracts_test.go +++ b/core/vm/contracts_test.go @@ -66,7 +66,7 @@ var allPrecompiles = map[common.Address]PrecompiledContract{ common.BytesToAddress([]byte{16}): &bls12381Pairing{}, common.BytesToAddress([]byte{17}): &bls12381MapG1{}, common.BytesToAddress([]byte{18}): &bls12381MapG2{}, - common.BytesToAddress([]byte{20}): &pointEvaluation{}, + common.BytesToAddress([]byte{20}): &kzgPointEvaluation{}, } // EIP-152 test vectors diff --git a/crypto/kzg4844/kzg4844.go b/crypto/kzg4844/kzg4844.go index 8798c712495ef..3bd814159db3a 100644 --- a/crypto/kzg4844/kzg4844.go +++ b/crypto/kzg4844/kzg4844.go @@ -41,8 +41,6 @@ type Point [32]byte // Claim is a claimed evaluation value in a specific point. type Claim [32]byte -var PrecompileReturnValue [64]byte - // useCKZG controls whether the cryptography should use the Go or C backend. var useCKZG atomic.Bool @@ -63,8 +61,6 @@ func UseCKZG(use bool) error { } else { gokzgIniter.Do(gokzgInit) } - // Compute the precompile return value using go-kzg - PrecompileReturnValue = goComputePrecompileReturnValue() return nil } diff --git a/crypto/kzg4844/kzg4844_gokzg.go b/crypto/kzg4844/kzg4844_gokzg.go index 2011f212fe87e..3f03bb52738e8 100644 --- a/crypto/kzg4844/kzg4844_gokzg.go +++ b/crypto/kzg4844/kzg4844_gokzg.go @@ -17,7 +17,6 @@ package kzg4844 import ( - "encoding/binary" "encoding/json" "sync" @@ -97,12 +96,3 @@ func gokzgVerifyBlobProof(blob Blob, commitment Commitment, proof Proof) error { return context.VerifyBlobKZGProof((gokzg4844.Blob)(blob), (gokzg4844.KZGCommitment)(commitment), (gokzg4844.KZGProof)(proof)) } - -// goComputePrecompileReturnValue computes the precompile return value which is -// FIELD_ELEMENTS_PER_BLOB and BLS_MODULUS as padded 32 byte big endian values. -func goComputePrecompileReturnValue() [64]byte { - var precompileReturnValue [64]byte - binary.BigEndian.PutUint64(precompileReturnValue[24:], gokzg4844.ScalarsPerBlob) - copy(precompileReturnValue[32:], gokzg4844.BlsModulus[:]) - return precompileReturnValue -} diff --git a/params/protocol_params.go b/params/protocol_params.go index b45e8d57af9eb..c662e4a3f385b 100644 --- a/params/protocol_params.go +++ b/params/protocol_params.go @@ -160,13 +160,13 @@ const ( RefundQuotient uint64 = 2 RefundQuotientEIP3529 uint64 = 5 - BlobTxHashVersion = 0x01 // Version byte of the commitment hash - BlobTxMaxDataGasPerBlock = 1 << 19 // Maximum consumable data gas for data blobs per block - BlobTxTargetDataGasPerBlock = 1 << 18 // Target consumable data gas for data blobs per block (for 1559-like pricing) - BlobTxDataGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size) - BlobTxMinDataGasprice = 1 // Minimum gas price for data blobs - BlobTxDataGaspriceUpdateFraction = 2225652 // Controls the maximum rate of change for data gas price - PointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. + BlobTxHashVersion = 0x01 // Version byte of the commitment hash + BlobTxMaxDataGasPerBlock = 1 << 19 // Maximum consumable data gas for data blobs per block + BlobTxTargetDataGasPerBlock = 1 << 18 // Target consumable data gas for data blobs per block (for 1559-like pricing) + BlobTxDataGasPerBlob = 1 << 17 // Gas consumption of a single data blob (== blob byte size) + BlobTxMinDataGasprice = 1 // Minimum gas price for data blobs + BlobTxDataGaspriceUpdateFraction = 2225652 // Controls the maximum rate of change for data gas price + BlobTxPointEvaluationPrecompileGas = 50000 // Gas price for the point evaluation precompile. ) // Gas discount table for BLS12-381 G1 and G2 multi exponentiation operations