Skip to content

Commit

Permalink
tests/4844: Add blob network type in block test (#164)
Browse files Browse the repository at this point in the history
* tests/4844: Add full blob class

* tests/4844: Add full blob test

* tests/4844: tx field rename

* tests/4844: extra assert in common

* tests/4844: more full blob tests

* fix: tox
  • Loading branch information
marioevz authored Jul 5, 2023
1 parent 5440994 commit 7f25c59
Show file tree
Hide file tree
Showing 2 changed files with 385 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/cancun/eip4844_blobs/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""
Common constants, classes & functions local to EIP-4844 tests.
"""
from dataclasses import dataclass
from hashlib import sha256
from typing import Literal, Union
from typing import List, Literal, Tuple, Union

from ethereum_test_tools import (
TestAddress,
Expand All @@ -26,6 +27,7 @@
BLS_MODULUS_BYTES = BLS_MODULUS.to_bytes(32, "big")
DATA_GAS_PER_BLOB = 2**17
DATA_GASPRICE_UPDATE_FRACTION = 3338477
BYTES_PER_FIELD_ELEMENT = 32
FIELD_ELEMENTS_PER_BLOB = 4096
FIELD_ELEMENTS_PER_BLOB_BYTES = FIELD_ELEMENTS_PER_BLOB.to_bytes(32, "big")
INF_POINT = (0xC0 << 376).to_bytes(48, byteorder="big")
Expand Down Expand Up @@ -121,6 +123,41 @@ def kzg_to_versioned_hash(
return blob_commitment_version_kzg + sha256(kzg_commitment).digest()[1:]


@dataclass(kw_only=True)
class Blob:
"""
Class representing a full blob.
"""

blob: bytes
kzg_commitment: bytes
kzg_proof: bytes

def versioned_hash(self) -> bytes:
"""
Calculates the versioned hash for a given blob.
"""
return kzg_to_versioned_hash(self.kzg_commitment)

@staticmethod
def blobs_to_transaction_input(
input_blobs: List["Blob"],
) -> Tuple[List[bytes], List[bytes], List[bytes]]:
"""
Returns a tuple of lists of blobs, kzg commitments formatted to be added to a network blob
type transaction.
"""
blobs: List[bytes] = []
kzg_commitments: List[bytes] = []
kzg_proofs: List[bytes] = []

for blob in input_blobs:
blobs.append(blob.blob)
kzg_commitments.append(blob.kzg_commitment)
kzg_proofs.append(blob.kzg_proof)
return (blobs, kzg_commitments, kzg_proofs)


# Simple list of blob versioned hashes ranging from bytes32(1 to 4)
simple_blob_hashes: list[bytes] = add_kzg_version(
[(1 << x) for x in range(MAX_BLOBS_PER_BLOCK)],
Expand Down Expand Up @@ -199,6 +236,8 @@ def code(cls, context_name):
"""
Maps an opcode context to bytecode that utilizes the BLOBHASH opcode.
"""
assert cls.yul_compiler is not None, "YulCompiler not set"

blobhash_verbatim = cls._get_blobhash_verbatim()

code = {
Expand Down
Loading

0 comments on commit 7f25c59

Please sign in to comment.