-
Notifications
You must be signed in to change notification settings - Fork 0
Witness generation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: forks/amsterdam
Are you sure you want to change the base?
Changes from all commits
a021e45
91f4ccf
208cfc4
2331b71
59b465f
d96947d
c3a1fbb
69002db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,7 +58,10 @@ | |
| increment_nonce, | ||
| modify_state, | ||
| set_account_balance, | ||
| set_witness_metadata, | ||
| state_root, | ||
| track_block_hash_access, | ||
| track_bytecode_access, | ||
| ) | ||
| from .transactions import ( | ||
| AccessListTransaction, | ||
|
|
@@ -191,6 +194,36 @@ def get_last_256_block_hashes(chain: BlockChain) -> List[Hash32]: | |
| return recent_block_hashes | ||
|
|
||
|
|
||
| def get_last_256_block_headers(chain: BlockChain) -> List[Bytes]: | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a helper method to feed the witness generator with the info that requires to add the ancestors in the header. In the worst case, it can need the last 256 ancestors -- it will include in the witness the minimal amount of them as required (see next code diff right after). |
||
| """ | ||
| Obtain the list of RLP-encoded headers of the previous 256 blocks. | ||
|
|
||
| This function will return less headers for the first 256 blocks. | ||
| The headers are parallel to the hashes from get_last_256_block_hashes. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| chain : | ||
| History and current state. | ||
|
|
||
| Returns | ||
| ------- | ||
| recent_block_headers : `List[Bytes]` | ||
| RLP-encoded headers of recent 256 blocks in order of increasing number. | ||
|
|
||
| """ | ||
| recent_blocks = chain.blocks[-256:] | ||
| if len(recent_blocks) == 0: | ||
| return [] | ||
|
|
||
| recent_block_headers: List[Bytes] = [] | ||
| for block in recent_blocks: | ||
| header_rlp = rlp.encode(block.header) | ||
| recent_block_headers.append(header_rlp) | ||
|
|
||
| return recent_block_headers | ||
|
|
||
|
|
||
| def state_transition(chain: BlockChain, block: Block) -> None: | ||
| """ | ||
| Attempts to apply a block to an existing block chain. | ||
|
|
@@ -235,6 +268,13 @@ def state_transition(chain: BlockChain, block: Block) -> None: | |
| parent_beacon_block_root=block.header.parent_beacon_block_root, | ||
| ) | ||
|
|
||
| # Set witness metadata if tracking is enabled | ||
| set_witness_metadata( | ||
| block_env.state, | ||
| block.header.number, | ||
| get_last_256_block_headers(chain), | ||
| ) | ||
|
|
||
| block_output = apply_body( | ||
| block_env=block_env, | ||
| transactions=block.transactions, | ||
|
|
@@ -676,6 +716,7 @@ def process_checked_system_transaction( | |
|
|
||
| """ | ||
| system_contract_code = get_account(block_env.state, target_address).code | ||
| track_bytecode_access(block_env.state, system_contract_code) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In both cases, we track that the bytecode is required for the witness. |
||
|
|
||
| if len(system_contract_code) == 0: | ||
| raise InvalidBlock( | ||
|
|
@@ -724,6 +765,7 @@ def process_unchecked_system_transaction( | |
|
|
||
| """ | ||
| system_contract_code = get_account(block_env.state, target_address).code | ||
| track_bytecode_access(block_env.state, system_contract_code) | ||
| return process_system_transaction( | ||
| block_env, | ||
| target_address, | ||
|
|
@@ -770,6 +812,9 @@ def apply_body( | |
| data=block_env.parent_beacon_block_root, | ||
| ) | ||
|
|
||
| # Track parent block access for witness (EIP-2935 system call) | ||
| track_block_hash_access(block_env.state, block_env.number - Uint(1)) | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the 2935 system contract being called right below (L820) -- we track the need of requiring the parent block hash as expected. |
||
|
|
||
| process_unchecked_system_transaction( | ||
| block_env=block_env, | ||
| target_address=HISTORY_STORAGE_ADDRESS, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is removing the old witness generator thing we included in the specs which use an external Reth tool. Since we generate it from the specs now, we can clean it up.