-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix eip4844 state transition functions
- Loading branch information
Showing
8 changed files
with
122 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Empty file.
28 changes: 28 additions & 0 deletions
28
tests/core/pyspec/eth2spec/test/eip4844/sanity/test_blocks.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from eth2spec.test.helpers.state import ( | ||
state_transition_and_sign_block | ||
) | ||
from eth2spec.test.helpers.block import ( | ||
build_empty_block_for_next_slot | ||
) | ||
from eth2spec.test.context import ( | ||
spec_state_test, | ||
with_eip4844_and_later, | ||
) | ||
from eth2spec.test.helpers.sharding import ( | ||
get_sample_opaque_tx, | ||
) | ||
|
||
|
||
@with_eip4844_and_later | ||
@spec_state_test | ||
def test_simple_blobs(spec, state): | ||
yield 'pre', state | ||
|
||
block = build_empty_block_for_next_slot(spec, state) | ||
opaque_tx, _, blob_kzgs = get_sample_opaque_tx(spec) | ||
block.body.blob_kzgs = blob_kzgs | ||
block.body.execution_payload.transactions = [opaque_tx] | ||
signed_block = state_transition_and_sign_block(spec, state, block) | ||
|
||
yield 'blocks', [signed_block] | ||
yield 'post', state |
14 changes: 4 additions & 10 deletions
14
tests/core/pyspec/eth2spec/test/eip4844/unittests/test_kzg.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
|
||
import random | ||
from eth2spec.test.helpers.constants import ( | ||
EIP4844, | ||
MINIMAL, | ||
) | ||
from eth2spec.test.helpers.sharding import ( | ||
create_blob, | ||
) | ||
from eth2spec.test.context import ( | ||
with_phases, | ||
spec_state_test, | ||
with_presets, | ||
) | ||
|
||
|
||
def _create_blob(spec): | ||
rng = random.Random(5566) | ||
return spec.Blob([ | ||
rng.randint(0, spec.BLS_MODULUS - 1) | ||
for _ in range(spec.FIELD_ELEMENTS_PER_BLOB) | ||
]) | ||
|
||
|
||
@with_phases([EIP4844]) | ||
@spec_state_test | ||
@with_presets([MINIMAL]) | ||
def test_blob_to_kzg(spec, state): | ||
blob = _create_blob(spec) | ||
blob = create_blob(spec) | ||
spec.blob_to_kzg(blob) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import random | ||
from eth2spec.utils.ssz.ssz_typing import ( | ||
Container, | ||
Bytes20, Bytes32, | ||
ByteList, | ||
List, | ||
Union, | ||
boolean, | ||
uint256, uint64, | ||
) | ||
from eth2spec.utils.ssz.ssz_impl import serialize | ||
|
||
|
||
# | ||
# Containers from EIP-4844 | ||
# | ||
MAX_CALLDATA_SIZE = 2**24 | ||
MAX_VERSIONED_HASHES_LIST_SIZE = 2**24 | ||
MAX_ACCESS_LIST_STORAGE_KEYS = 2**24 | ||
MAX_ACCESS_LIST_SIZE = 2**24 | ||
|
||
|
||
class AccessTuple(Container): | ||
address: Bytes20 # Address = Bytes20 | ||
storage_keys: List[Bytes32, MAX_ACCESS_LIST_STORAGE_KEYS] | ||
|
||
|
||
class ECDSASignature(Container): | ||
y_parity: boolean | ||
r: uint256 | ||
s: uint256 | ||
|
||
|
||
class BlobTransaction(Container): | ||
chain_id: uint256 | ||
nonce: uint64 | ||
priority_fee_per_gas: uint256 | ||
max_basefee_per_gas: uint256 | ||
gas: uint64 | ||
to: Union[None, Bytes20] # Address = Bytes20 | ||
value: uint256 | ||
data: ByteList[MAX_CALLDATA_SIZE] | ||
access_list: List[AccessTuple, MAX_ACCESS_LIST_SIZE] | ||
blob_versioned_hashes: List[Bytes32, MAX_VERSIONED_HASHES_LIST_SIZE] | ||
|
||
|
||
class SignedBlobTransaction(Container): | ||
message: BlobTransaction | ||
signature: ECDSASignature | ||
|
||
|
||
def create_blob(spec, rng=None): | ||
if rng is None: | ||
rng = random.Random(5566) | ||
|
||
return spec.Blob([ | ||
rng.randint(0, spec.BLS_MODULUS - 1) | ||
for _ in range(spec.FIELD_ELEMENTS_PER_BLOB) | ||
]) | ||
|
||
|
||
def get_sample_opaque_tx(spec, blob_count=1, rng=None): | ||
blobs = [] | ||
blob_kzgs = [] | ||
blob_versioned_hashes = [] | ||
for _ in range(blob_count): | ||
blob = create_blob(spec, rng) | ||
blob_kzg = spec.KZGCommitment(spec.blob_to_kzg(blob)) | ||
blob_versioned_hash = spec.kzg_to_versioned_hash(blob_kzg) | ||
blobs.append(blob) | ||
blob_kzgs.append(blob_kzg) | ||
blob_versioned_hashes.append(blob_versioned_hash) | ||
|
||
signed_blob_tx = SignedBlobTransaction( | ||
message=BlobTransaction( | ||
blob_versioned_hashes=blob_versioned_hashes, | ||
) | ||
) | ||
serialized_tx = serialize(signed_blob_tx) | ||
opaque_tx = spec.uint_to_bytes(spec.BLOB_TX_TYPE) + serialized_tx | ||
return opaque_tx, blobs, blob_kzgs |
This file contains 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