mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-25 18:35:32 +00:00
Fix outdated EIP-4844 constants
This commit is contained in:
parent
8773eb609d
commit
820525d78c
@ -368,7 +368,7 @@ func versionedHashes(bb: BlobsBundleV1): seq[BlockHash] =
|
|||||||
|
|
||||||
for com in bb.commitments:
|
for com in bb.commitments:
|
||||||
var h = keccakHash(com.bytes)
|
var h = keccakHash(com.bytes)
|
||||||
h.data[0] = BLOB_COMMITMENT_VERSION_KZG
|
h.data[0] = VERSIONED_HASH_VERSION_KZG
|
||||||
result.add BlockHash(h.data)
|
result.add BlockHash(h.data)
|
||||||
|
|
||||||
proc broadcastNewPayload(cl: CLMocker, payload: ExecutionPayload): Result[PayloadStatusV1, string] =
|
proc broadcastNewPayload(cl: CLMocker, payload: ExecutionPayload): Result[PayloadStatusV1, string] =
|
||||||
|
@ -76,13 +76,13 @@ const
|
|||||||
MAX_ACCESS_LIST_SIZE* = 1 shl 24 # 2^24
|
MAX_ACCESS_LIST_SIZE* = 1 shl 24 # 2^24
|
||||||
MAX_ACCESS_LIST_STORAGE_KEYS* = 1 shl 24 # 2^24
|
MAX_ACCESS_LIST_STORAGE_KEYS* = 1 shl 24 # 2^24
|
||||||
MAX_TX_WRAP_COMMITMENTS* = 1 shl 12 # 2^12
|
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
|
FIELD_ELEMENTS_PER_BLOB* = 4096
|
||||||
GAS_PER_BLOB* = (1 shl 17).uint64 # 2^17
|
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
|
MIN_BLOB_GASPRICE* = 1'u64
|
||||||
BLOB_GASPRICE_UPDATE_FRACTION* = 2225652'u64
|
BLOB_GASPRICE_UPDATE_FRACTION* = 3338477'u64
|
||||||
MAX_BLOB_GAS_PER_BLOCK* = (1 shl 19).uint64 # 2^19
|
MAX_BLOB_GAS_PER_BLOCK* = 786432
|
||||||
MaxAllowedBlob* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
|
MAX_ALLOWED_BLOB* = MAX_BLOB_GAS_PER_BLOCK div GAS_PER_BLOB
|
||||||
|
|
||||||
# End
|
# End
|
||||||
|
@ -40,7 +40,7 @@ const
|
|||||||
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
# kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
|
||||||
proc kzgToVersionedHash(kzg: kzg.KZGCommitment): VersionedHash =
|
proc kzgToVersionedHash(kzg: kzg.KZGCommitment): VersionedHash =
|
||||||
result = keccakHash(kzg)
|
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
|
# pointEvaluation implements point_evaluation_precompile from EIP-4844
|
||||||
# return value and gas consumption is handled by pointEvaluation in
|
# 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]
|
commitment[0..<48] = input[96..<144]
|
||||||
kzgProof[0..<48] = input[144..<192]
|
kzgProof[0..<48] = input[144..<192]
|
||||||
|
|
||||||
|
if kzgToVersionedHash(commitment).data != versionedHash:
|
||||||
|
return err("versionedHash should equal to kzgToVersionedHash(commitment)")
|
||||||
|
|
||||||
# Verify KZG proof
|
# Verify KZG proof
|
||||||
let res = kzg.verifyKzgProof(commitment, z, y, kzgProof)
|
let res = kzg.verifyKzgProof(commitment, z, y, kzgProof)
|
||||||
if res.isErr:
|
if res.isErr:
|
||||||
@ -197,7 +200,7 @@ proc validateBlobTransactionWrapper*(tx: Transaction):
|
|||||||
# Now that all commitments have been verified, check that versionedHashes matches the commitments
|
# Now that all commitments have been verified, check that versionedHashes matches the commitments
|
||||||
for i in 0 ..< tx.versionedHashes.len:
|
for i in 0 ..< tx.versionedHashes.len:
|
||||||
# this additional check also done in tx validation
|
# 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)
|
return err("wrong kzg version in versioned hash at index " & $i)
|
||||||
|
|
||||||
if tx.versionedHashes[i] != kzgToVersionedHash(tx.networkPayload.commitments[i]):
|
if tx.versionedHashes[i] != kzgToVersionedHash(tx.networkPayload.commitments[i]):
|
||||||
|
@ -287,14 +287,14 @@ proc validateTxBasic*(
|
|||||||
if tx.versionedHashes.len == 0:
|
if tx.versionedHashes.len == 0:
|
||||||
return err("invalid tx: there must be at least one blob")
|
return err("invalid tx: there must be at least one blob")
|
||||||
|
|
||||||
if tx.versionedHashes.len > MaxAllowedBlob.int:
|
if tx.versionedHashes.len > MAX_ALLOWED_BLOB.int:
|
||||||
return err("invalid tx: versioned hashes len exceeds MaxAllowedBlob=" & $MaxAllowedBlob &
|
return err("invalid tx: versioned hashes len exceeds MAX_ALLOWED_BLOB=" & $MAX_ALLOWED_BLOB &
|
||||||
". get=" & $tx.versionedHashes.len)
|
". get=" & $tx.versionedHashes.len)
|
||||||
|
|
||||||
for i, bv in tx.versionedHashes:
|
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. " &
|
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:
|
except CatchableError as ex:
|
||||||
return err(ex.msg)
|
return err(ex.msg)
|
||||||
|
@ -47,12 +47,7 @@ type
|
|||||||
# paBlsMapG1
|
# paBlsMapG1
|
||||||
# paBlsMapG2
|
# paBlsMapG2
|
||||||
# Cancun
|
# Cancun
|
||||||
paNoop0x0A, paNoop0x0B, paNoop0x0C,
|
paPointEvaluation = 0x0A
|
||||||
paNoop0x0D, paNoop0x0E, paNoop0x0F,
|
|
||||||
paNoop0x10, paNoop0x11, paNoop0x12,
|
|
||||||
paNoop0x13,
|
|
||||||
|
|
||||||
paPointEvaluation = 0x14
|
|
||||||
|
|
||||||
proc getMaxPrecompileAddr(fork: EVMFork): PrecompileAddresses =
|
proc getMaxPrecompileAddr(fork: EVMFork): PrecompileAddresses =
|
||||||
if fork < FkByzantium: paIdentity
|
if fork < FkByzantium: paIdentity
|
||||||
@ -64,8 +59,7 @@ proc getMaxPrecompileAddr(fork: EVMFork): PrecompileAddresses =
|
|||||||
else: PrecompileAddresses.high
|
else: PrecompileAddresses.high
|
||||||
|
|
||||||
proc validPrecompileAddr(addrByte, maxPrecompileAddr: byte): bool =
|
proc validPrecompileAddr(addrByte, maxPrecompileAddr: byte): bool =
|
||||||
(addrByte in PrecompileAddresses.low.byte .. maxPrecompileAddr) and
|
(addrByte in PrecompileAddresses.low.byte .. maxPrecompileAddr)
|
||||||
(addrByte notin paNoop0x0A.byte .. paNoop0x13.byte)
|
|
||||||
|
|
||||||
proc validPrecompileAddr(addrByte: byte, fork: EVMFork): bool =
|
proc validPrecompileAddr(addrByte: byte, fork: EVMFork): bool =
|
||||||
let maxPrecompileAddr = getMaxPrecompileAddr(fork)
|
let maxPrecompileAddr = getMaxPrecompileAddr(fork)
|
||||||
|
@ -139,11 +139,11 @@ proc validateTxEip4844(tx: Transaction) =
|
|||||||
(acl.storageKeys.len <= MAX_ACCESS_LIST_STORAGE_KEYS)
|
(acl.storageKeys.len <= MAX_ACCESS_LIST_STORAGE_KEYS)
|
||||||
|
|
||||||
isValid = isValid and
|
isValid = isValid and
|
||||||
tx.versionedHashes.len <= MaxAllowedBlob.int
|
tx.versionedHashes.len <= MAX_ALLOWED_BLOB.int
|
||||||
|
|
||||||
for bv in tx.versionedHashes:
|
for bv in tx.versionedHashes:
|
||||||
isValid = isValid and
|
isValid = isValid and
|
||||||
bv.data[0] == BLOB_COMMITMENT_VERSION_KZG
|
bv.data[0] == VERSIONED_HASH_VERSION_KZG
|
||||||
|
|
||||||
if not isValid:
|
if not isValid:
|
||||||
raise newException(ValidationError, "Invalid EIP-4844 transaction")
|
raise newException(ValidationError, "Invalid EIP-4844 transaction")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user