Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request 0xPolygonZero#1206 from topos-protocol/missing-pub…
Browse files Browse the repository at this point in the history
…lic-value-links

Add missing links between public values
  • Loading branch information
LindaGuiga authored Sep 6, 2023
2 parents a709654 + d4b71c5 commit 6207f44
Show file tree
Hide file tree
Showing 17 changed files with 1,206 additions and 105 deletions.
73 changes: 69 additions & 4 deletions evm/src/cpu/kernel/asm/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ global main:
// First, initialise the shift table
%shift_table_init

// Initialize the block bloom filter
%initialize_block_bloom

// Second, load all MPT data from the prover.
PUSH hash_initial_tries
%jump(load_all_mpts)
Expand All @@ -13,9 +16,8 @@ global hash_initial_tries:

global start_txns:
// stack: (empty)
// Last mpt input is txn_nb.
PROVER_INPUT(mpt)
PUSH 0
%mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_BEFORE)
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_BEFORE)
// stack: init_used_gas, txn_nb

txn_loop:
Expand All @@ -37,8 +39,71 @@ global txn_loop_after:

global hash_final_tries:
// stack: cum_gas, txn_nb
%pop2
// Check that we end up with the correct `cum_gas`, `txn_nb` and bloom filter.
%mload_global_metadata(@GLOBAL_METADATA_BLOCK_GAS_USED_AFTER) %assert_eq
%mload_global_metadata(@GLOBAL_METADATA_TXN_NUMBER_AFTER) %assert_eq
%check_metadata_block_bloom
%mpt_hash_state_trie %mload_global_metadata(@GLOBAL_METADATA_STATE_TRIE_DIGEST_AFTER) %assert_eq
%mpt_hash_txn_trie %mload_global_metadata(@GLOBAL_METADATA_TXN_TRIE_DIGEST_AFTER) %assert_eq
%mpt_hash_receipt_trie %mload_global_metadata(@GLOBAL_METADATA_RECEIPT_TRIE_DIGEST_AFTER) %assert_eq
%jump(halt)

initialize_block_bloom:
// stack: retdest
PUSH 0 PUSH 8 PUSH 0

initialize_bloom_loop:
// stack: i, len, offset, retdest
DUP2 DUP2 EQ %jumpi(initialize_bloom_loop_end)
PUSH 32 // Bloom word length
// stack: word_len, i, len, offset, retdest
// Load the next `block_bloom_before` word.
DUP2 %add_const(8) %mload_kernel(@SEGMENT_GLOBAL_BLOCK_BLOOM)
// stack: bloom_word, word_len, i, len, offset, retdest
DUP5 PUSH @SEGMENT_BLOCK_BLOOM PUSH 0 // Bloom word address in SEGMENT_BLOCK_BLOOM
%mstore_unpacking
// stack: new_offset, i, len, old_offset, retdest
SWAP3 POP %increment
// stack: i, len, new_offset, retdest
%jump(initialize_bloom_loop)

initialize_bloom_loop_end:
// stack: len, len, offset, retdest
%pop3
JUMP
%macro initialize_block_bloom
// stack: (empty)
PUSH %%after
%jump(initialize_block_bloom)
%%after:
%endmacro

check_metadata_block_bloom:
// stack: retdest
PUSH 0 PUSH 8 PUSH 0

check_bloom_loop:
// stack: i, len, offset, retdest
DUP2 DUP2 EQ %jumpi(check_bloom_loop_end)
PUSH 32 // Bloom word length
// stack: word_len, i, len, offset, retdest
DUP4 PUSH @SEGMENT_BLOCK_BLOOM PUSH 0
%mload_packing
// stack: bloom_word, i, len, offset, retdest
DUP2 %add_const(16) %mload_kernel(@SEGMENT_GLOBAL_BLOCK_BLOOM) %assert_eq
// stack: i, len, offset, retdest
%increment SWAP2 %add_const(32) SWAP2
// stack: i+1, len, new_offset, retdest
%jump(check_bloom_loop)

check_bloom_loop_end:
// stack: len, len, offset, retdest
%pop3
JUMP

%macro check_metadata_block_bloom
PUSH %%after
%jump(check_metadata_block_bloom)
%%after:
%endmacro
58 changes: 37 additions & 21 deletions evm/src/cpu/kernel/constants/global_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,49 @@ pub(crate) enum GlobalMetadata {
BlockGasLimit = 18,
BlockChainId = 19,
BlockBaseFee = 20,

BlockGasUsed = 21,
/// Before current transactions block values.
BlockGasUsedBefore = 22,
/// After current transactions block values.
BlockGasUsedAfter = 23,
/// Gas to refund at the end of the transaction.
RefundCounter = 21,
RefundCounter = 24,
/// Length of the addresses access list.
AccessedAddressesLen = 22,
AccessedAddressesLen = 25,
/// Length of the storage keys access list.
AccessedStorageKeysLen = 23,
AccessedStorageKeysLen = 26,
/// Length of the self-destruct list.
SelfDestructListLen = 24,
SelfDestructListLen = 27,
/// Length of the bloom entry buffer.
BloomEntryLen = 25,
BloomEntryLen = 28,

/// Length of the journal.
JournalLen = 26,
JournalLen = 29,
/// Length of the `JournalData` segment.
JournalDataLen = 27,
JournalDataLen = 30,
/// Current checkpoint.
CurrentCheckpoint = 28,
TouchedAddressesLen = 29,
CurrentCheckpoint = 31,
TouchedAddressesLen = 32,
// Gas cost for the access list in type-1 txns. See EIP-2930.
AccessListDataCost = 30,
AccessListDataCost = 33,
// Start of the access list in the RLP for type-1 txns.
AccessListRlpStart = 31,
AccessListRlpStart = 34,
// Length of the access list in the RLP for type-1 txns.
AccessListRlpLen = 32,
AccessListRlpLen = 35,
// Boolean flag indicating if the txn is a contract creation txn.
ContractCreation = 33,
IsPrecompileFromEoa = 34,
CallStackDepth = 35,
/// Transaction logs list length
LogsLen = 36,
LogsDataLen = 37,
LogsPayloadLen = 38,
ContractCreation = 36,
IsPrecompileFromEoa = 37,
CallStackDepth = 38,
/// Transaction logs list length.
LogsLen = 39,
LogsDataLen = 40,
LogsPayloadLen = 41,
TxnNumberBefore = 42,
TxnNumberAfter = 43,
}

impl GlobalMetadata {
pub(crate) const COUNT: usize = 39;
pub(crate) const COUNT: usize = 44;

pub(crate) fn all() -> [Self; Self::COUNT] {
[
Expand All @@ -103,6 +109,9 @@ impl GlobalMetadata {
Self::BlockGasLimit,
Self::BlockChainId,
Self::BlockBaseFee,
Self::BlockGasUsed,
Self::BlockGasUsedBefore,
Self::BlockGasUsedAfter,
Self::RefundCounter,
Self::AccessedAddressesLen,
Self::AccessedStorageKeysLen,
Expand All @@ -121,6 +130,8 @@ impl GlobalMetadata {
Self::LogsLen,
Self::LogsDataLen,
Self::LogsPayloadLen,
Self::TxnNumberBefore,
Self::TxnNumberAfter,
]
}

Expand Down Expand Up @@ -148,6 +159,9 @@ impl GlobalMetadata {
Self::BlockGasLimit => "GLOBAL_METADATA_BLOCK_GAS_LIMIT",
Self::BlockChainId => "GLOBAL_METADATA_BLOCK_CHAIN_ID",
Self::BlockBaseFee => "GLOBAL_METADATA_BLOCK_BASE_FEE",
Self::BlockGasUsed => "GLOBAL_METADATA_BLOCK_GAS_USED",
Self::BlockGasUsedBefore => "GLOBAL_METADATA_BLOCK_GAS_USED_BEFORE",
Self::BlockGasUsedAfter => "GLOBAL_METADATA_BLOCK_GAS_USED_AFTER",
Self::RefundCounter => "GLOBAL_METADATA_REFUND_COUNTER",
Self::AccessedAddressesLen => "GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN",
Self::AccessedStorageKeysLen => "GLOBAL_METADATA_ACCESSED_STORAGE_KEYS_LEN",
Expand All @@ -166,6 +180,8 @@ impl GlobalMetadata {
Self::LogsLen => "GLOBAL_METADATA_LOGS_LEN",
Self::LogsDataLen => "GLOBAL_METADATA_LOGS_DATA_LEN",
Self::LogsPayloadLen => "GLOBAL_METADATA_LOGS_PAYLOAD_LEN",
Self::TxnNumberBefore => "GLOBAL_METADATA_TXN_NUMBER_BEFORE",
Self::TxnNumberAfter => "GLOBAL_METADATA_TXN_NUMBER_AFTER",
}
}
}
Loading

0 comments on commit 6207f44

Please sign in to comment.