Skip to content

Commit 4382738

Browse files
authored
Merge pull request ethereum#45 from quilt/review-feedback
Review feedback
2 parents 58ce043 + b02b24d commit 4382738

File tree

7 files changed

+26
-18
lines changed

7 files changed

+26
-18
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tests/fixtures"]
2-
path = tests/fixtures
3-
url = https://github.com/ethereum/tests
2+
path = tests/fixtures
3+
url = https://github.com/ethereum/tests
44
branch = develop

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Eth1.0 Specifications
22

3-
### Description
3+
## Description
44

55
This repository contains various specification related to the Ethereum 1.0 chain, specifically the [pyspec](/src/eth1spec/spec.py), specifications for [network upgrades](/network-upgrades), and the [JSON RPC API](/json-rpc).
66

@@ -25,6 +25,8 @@ This repository contains various specification related to the Ethereum 1.0 chain
2525

2626
## Consensus Specification (work-in-progress)
2727

28+
The consensus specification is a python implementation of Ethereum that prioritizes readability and simplicity. It [will] accompanied by both narrative and API level documentation of the various components written in restructured text and rendered using Sphinx....
29+
2830
* [Rendered specification](https://quilt.github.io/eth1.0-specs/)
2931

3032
## Usage
@@ -87,7 +89,7 @@ This specification aims to be:
8789

8890
1. **Correct** - Describe the _intended_ behavior of the Ethereum blockchain, and any deviation from that is a bug.
8991
2. **Complete** - Capture the entirety of _consensus critical_ parts of Ethereum.
90-
3. **Usable** - Prioritize readability, clarity, and plain language over performance and brevity.
92+
3. **Accessible** - Prioritize readability, clarity, and plain language over performance and brevity.
9193

9294
### Spelling
9395

src/eth1spec/evm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Evm:
4545

4646
pc: Uint
4747
stack: List[U256]
48-
memory: bytes
48+
memory: bytearray
4949
code: bytes
5050
gas_left: U256
5151
current: Address

src/eth1spec/evm/instructions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def add(evm: Evm) -> None:
4141
x = pop(evm.stack)
4242
y = pop(evm.stack)
4343

44-
val = x + y
44+
val = x.wrapping_add(y)
4545

4646
push(evm.stack, val)
4747

src/eth1spec/evm/interpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def process_call(
6565
evm = Evm(
6666
pc=Uint(0),
6767
stack=[],
68-
memory=b"",
68+
memory=bytearray(),
6969
code=env.state[target].code,
7070
gas_left=gas,
7171
current=target,

src/eth1spec/spec.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,14 @@ def apply_body(
171171

172172
state[coinbase].balance += BLOCK_REWARD
173173

174+
gas_remaining = block_gas_limit - gas_available
175+
174176
receipts_map = {
175177
bytes(rlp.encode(Uint(k))): v for (k, v) in enumerate(receipts)
176178
}
177-
receipts_y = trie.map_keys(receipts_map, secured=False)
178-
return (block_gas_limit - gas_available), trie.root(receipts_y), state
179+
receipt_root = trie.root(trie.map_keys(receipts_map, secured=False))
180+
181+
return (gas_remaining, receipt_root, state)
179182

180183

181184
def process_transaction(
@@ -198,7 +201,7 @@ def process_transaction(
198201
logs : `List[eth1spec.eth_types.Log]`
199202
Logs generated during execution.
200203
"""
201-
assert verify_transaction(tx)
204+
assert validate_transaction(tx)
202205

203206
sender_address = env.origin
204207
sender = env.state[sender_address]
@@ -210,7 +213,7 @@ def process_transaction(
210213
assert cost <= sender.balance
211214
sender.balance -= cost
212215

213-
gas = tx.gas - intrinsic_cost(tx)
216+
gas = tx.gas - calculate_intrinsic_cost(tx)
214217

215218
if tx.to is None:
216219
raise NotImplementedError() # TODO
@@ -226,24 +229,24 @@ def process_transaction(
226229
return (gas_used, logs)
227230

228231

229-
def verify_transaction(tx: Transaction) -> bool:
232+
def validate_transaction(tx: Transaction) -> bool:
230233
"""
231234
Verifies a transaction.
232235
233236
Parameters
234237
----------
235238
tx : `eth1spec.eth_types.Transaction`
236-
Transaction to verify.
239+
Transaction to validate.
237240
238241
Returns
239242
-------
240243
verified : `bool`
241244
True if the transaction can be executed, or False otherwise.
242245
"""
243-
return intrinsic_cost(tx) <= tx.gas
246+
return calculate_intrinsic_cost(tx) <= tx.gas
244247

245248

246-
def intrinsic_cost(tx: Transaction) -> Uint:
249+
def calculate_intrinsic_cost(tx: Transaction) -> Uint:
247250
"""
248251
Calculates the intrinsic cost of the transaction that is charged before
249252
execution is instantiated.

src/eth1spec/trie.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ def map_keys(
110110

111111
nibble_list = bytearray(2 * len(key))
112112
for i in range(2 * len(key)):
113-
if i % 2 == 0: # even
114-
nibble_list[i] = key[i // 2] // 16
113+
byte_idx = i // 2
114+
if i % 2 == 0:
115+
# get upper nibble
116+
nibble_list[i] = (key[byte_idx] & 0xF0) >> 4
115117
else:
116-
nibble_list[i] = key[i // 2] % 16
118+
# get lower nibble
119+
nibble_list[i] = key[byte_idx] & 0x0F
117120

118121
mapped[Bytes(nibble_list)] = value
119122

0 commit comments

Comments
 (0)