Fix outdated EIP-4844 constants

This commit is contained in:
jangko 2023-08-24 12:11:19 +07:00
parent 8773eb609d
commit 820525d78c
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
6 changed files with 19 additions and 22 deletions

View File

@ -368,7 +368,7 @@ func versionedHashes(bb: BlobsBundleV1): seq[BlockHash] =
for com in bb.commitments:
var h = keccakHash(com.bytes)
h.data[0] = BLOB_COMMITMENT_VERSION_KZG
h.data[0] = VERSIONED_HASH_VERSION_KZG
result.add BlockHash(h.data)
proc broadcastNewPayload(cl: CLMocker, payload: ExecutionPayload): Result[PayloadStatusV1, string] =

View File

@ -76,13 +76,13 @@ const
MAX_ACCESS_LIST_SIZE* = 1 shl 24 # 2^24
MAX_ACCESS_LIST_STORAGE_KEYS* = 1 shl 24 # 2^24
MAX_TX_WRAP_COMMITMENTS* = 1 shl 12 # 2^12
BLOB_COMMITMENT_VERSION_KZG* = 0x01.byte
VERSIONED_HASH_VERSION_KZG* = 0x01.byte
FIELD_ELEMENTS_PER_BLOB* = 4096
GAS_PER_BLOB* = (1 shl 17).uint64 # 2^17
TARGET_BLOB_GAS_PER_BLOCK* = (1 shl 18).uint64 # 2^18
TARGET_BLOB_GAS_PER_BLOCK* = 393216
MIN_BLOB_GASPRICE* = 1'u64
BLOB_GASPRICE_UPDATE_FRACTION* = 2225652'u64
MAX_BLOB_GAS_PER_BLOCK* = (1 shl 19).uint64 # 2^19
MaxAllowedBlob* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
BLOB_GASPRICE_UPDATE_FRACTION* = 3338477'u64
MAX_BLOB_GAS_PER_BLOCK* = 786432
MAX_ALLOWED_BLOB* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
# End

View File

@ -40,7 +40,7 @@ const
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
proc kzgToVersionedHash(kzg: kzg.KZGCommitment): VersionedHash =
result = keccakHash(kzg)
result.data[0] = BLOB_COMMITMENT_VERSION_KZG
result.data[0] = VERSIONED_HASH_VERSION_KZG
# pointEvaluation implements point_evaluation_precompile from EIP-4844
# return value and gas consumption is handled by pointEvaluation in
@ -66,6 +66,9 @@ proc pointEvaluation*(input: openArray[byte]): Result[void, string] =
commitment[0..<48] = input[96..<144]
kzgProof[0..<48] = input[144..<192]
if kzgToVersionedHash(commitment).data != versionedHash:
return err("versionedHash should equal to kzgToVersionedHash(commitment)")
# Verify KZG proof
let res = kzg.verifyKzgProof(commitment, z, y, kzgProof)
if res.isErr:
@ -197,7 +200,7 @@ proc validateBlobTransactionWrapper*(tx: Transaction):
# Now that all commitments have been verified, check that versionedHashes matches the commitments
for i in 0 ..< tx.versionedHashes.len:
# this additional check also done in tx validation
if tx.versionedHashes[i].data[0] != BLOB_COMMITMENT_VERSION_KZG:
if tx.versionedHashes[i].data[0] != VERSIONED_HASH_VERSION_KZG:
return err("wrong kzg version in versioned hash at index " & $i)
if tx.versionedHashes[i] != kzgToVersionedHash(tx.networkPayload.commitments[i]):

View File

@ -287,14 +287,14 @@ proc validateTxBasic*(
if tx.versionedHashes.len == 0:
return err("invalid tx: there must be at least one blob")
if tx.versionedHashes.len > MaxAllowedBlob.int:
return err("invalid tx: versioned hashes len exceeds MaxAllowedBlob=" & $MaxAllowedBlob &
if tx.versionedHashes.len > MAX_ALLOWED_BLOB.int:
return err("invalid tx: versioned hashes len exceeds MAX_ALLOWED_BLOB=" & $MAX_ALLOWED_BLOB &
". get=" & $tx.versionedHashes.len)
for i, bv in tx.versionedHashes:
if bv.data[0] != BLOB_COMMITMENT_VERSION_KZG:
if bv.data[0] != VERSIONED_HASH_VERSION_KZG:
return err("invalid tx: one of blobVersionedHash has invalid version. " &
"get=$1, expect=$2" % [$bv.data[0].int, $BLOB_COMMITMENT_VERSION_KZG.int])
"get=$1, expect=$2" % [$bv.data[0].int, $VERSIONED_HASH_VERSION_KZG.int])
except CatchableError as ex:
return err(ex.msg)

View File

@ -47,12 +47,7 @@ type
# paBlsMapG1
# paBlsMapG2
# Cancun
paNoop0x0A, paNoop0x0B, paNoop0x0C,
paNoop0x0D, paNoop0x0E, paNoop0x0F,
paNoop0x10, paNoop0x11, paNoop0x12,
paNoop0x13,
paPointEvaluation = 0x14
paPointEvaluation = 0x0A
proc getMaxPrecompileAddr(fork: EVMFork): PrecompileAddresses =
if fork < FkByzantium: paIdentity
@ -64,8 +59,7 @@ proc getMaxPrecompileAddr(fork: EVMFork): PrecompileAddresses =
else: PrecompileAddresses.high
proc validPrecompileAddr(addrByte, maxPrecompileAddr: byte): bool =
(addrByte in PrecompileAddresses.low.byte .. maxPrecompileAddr) and
(addrByte notin paNoop0x0A.byte .. paNoop0x13.byte)
(addrByte in PrecompileAddresses.low.byte .. maxPrecompileAddr)
proc validPrecompileAddr(addrByte: byte, fork: EVMFork): bool =
let maxPrecompileAddr = getMaxPrecompileAddr(fork)

View File

@ -139,11 +139,11 @@ proc validateTxEip4844(tx: Transaction) =
(acl.storageKeys.len <= MAX_ACCESS_LIST_STORAGE_KEYS)
isValid = isValid and
tx.versionedHashes.len <= MaxAllowedBlob.int
tx.versionedHashes.len <= MAX_ALLOWED_BLOB.int
for bv in tx.versionedHashes:
isValid = isValid and
bv.data[0] == BLOB_COMMITMENT_VERSION_KZG
bv.data[0] == VERSIONED_HASH_VERSION_KZG
if not isValid:
raise newException(ValidationError, "Invalid EIP-4844 transaction")