Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ jobs:
make install
- name: Lint
run: make lint
- name: Type check
run: make type
- name: Test with pytest
run: make test
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ lint: ## Check whether the code is formated correctly
black . --check
mdformat specs/ --number --check

type: ## Check the typing of the Python code
mypy src

test: ## Run tests
pytest

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ test =
lint =
black >= 22.1.0
mdformat >= 0.7.13
mypy >= 0.931
4 changes: 2 additions & 2 deletions src/zkevm_specs/bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def select(
when_true: U256,
when_false: U256,
) -> U256:
return selector * when_true + (1 - selector) * when_false
return U256(selector * when_true + (1 - selector) * when_false)


@is_circuit_code
Expand Down Expand Up @@ -178,7 +178,7 @@ def assign_push_table():


# Generate keccak table
def assign_keccak_table(bytecodes: Sequence[bytes], randomness: int):
def assign_keccak_table(bytecodes: Sequence[bytes], randomness: FQ):
keccak_table = []
for bytecode in bytecodes:
hash = RLC(bytes(reversed(keccak256(bytecode))), randomness)
Expand Down
2 changes: 1 addition & 1 deletion src/zkevm_specs/encoding/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class LookupTable:
columns: Tuple[str]
columns: Tuple[str, ...]
rows: Set[Tuple[int, ...]]

def __init__(self, columns: Sequence[str]) -> None:
Expand Down
12 changes: 6 additions & 6 deletions src/zkevm_specs/encoding/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Sequence, Tuple, List
from typing import Sequence, Tuple
from .typing import U8, U256, U64


def is_circuit_code(func) -> object:
def is_circuit_code(func):
"""
A no-op decorator just to mark the function
"""
Expand All @@ -15,19 +15,19 @@ def wrapper(*args, **kargs):

def u256_to_u8s(x: U256) -> Tuple[U8, ...]:
assert 0 <= x < 2**256, "expect x is unsigned 256 bits"
return tuple((x >> 8 * i) & 0xFF for i in range(32))
return tuple(U8((x >> 8 * i) & 0xFF) for i in range(32))


def u256_to_u64s(x: U256) -> Tuple[U64, ...]:
assert 0 <= x < 2**256, "expect x is unsigned 256 bits"
return tuple((x >> 64 * i) & 0xFFFFFFFFFFFFFFFF for i in range(4))
return tuple(U64((x >> 64 * i) & 0xFFFFFFFFFFFFFFFF) for i in range(4))


def u8s_to_u256(xs: Sequence[U8]) -> U256:
assert len(xs) == 32
for u8 in xs:
assert 0 <= u8 <= 255
return sum(x * (2 ** (8 * i)) for i, x in enumerate(xs))
return U256(sum(x * (2 ** (8 * i)) for i, x in enumerate(xs)))


# [u8;32]->[u64;4]
Expand All @@ -37,5 +37,5 @@ def u8s_to_u64s(xs: Sequence[U8]) -> Tuple[U64, ...]:
A = [u64_0] * 4 # A = A3A2A1A0
for i in range(4):
for j in range(8):
A[i] += U64(xs[j + 8 * i] * (2 ** (8 * j)))
A[i] += xs[j + 8 * i] * (2 ** (8 * j))
return tuple(A)
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from typing import Callable, Dict

from ..execution_state import ExecutionState
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/add.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..opcode import Opcode

Expand Down
3 changes: 2 additions & 1 deletion src/zkevm_specs/evm/execution/begin_tx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ...util import GAS_COST_TX, GAS_COST_CREATION_TX, EMPTY_CODE_HASH
# type: ignore
from ...util import GAS_COST_TX, GAS_COST_CREATION_TX, EMPTY_CODE_HASH, RLC
from ..execution_state import ExecutionState
from ..instruction import Instruction, Transition
from ..precompiled import PrecompiledAddress
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/block_coinbase.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import BlockContextFieldTag
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/block_timestamp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import BlockContextFieldTag
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/calldatacopy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ...util import N_BYTES_MEMORY_ADDRESS, FQ
from ..execution_state import ExecutionState
from ..instruction import Instruction, Transition
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/calldatasize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import CallContextFieldTag
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/caller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import CallContextFieldTag
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/callvalue.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import CallContextFieldTag
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/end_block.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import CallContextFieldTag

Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/end_tx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ...util import N_BYTES_GAS, MAX_REFUND_QUOTIENT_OF_GAS_USED
from ..execution_state import ExecutionState
from ..instruction import Instruction, Transition
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/gas.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..opcode import Opcode
from ..table import CallContextFieldTag, TxContextFieldTag
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/gasprice.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..opcode import Opcode
from ..table import CallContextFieldTag, TxContextFieldTag
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/jump.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ...util.param import N_BYTES_PROGRAM_COUNTER
from ..instruction import Instruction, Transition
from ..opcode import Opcode
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/jumpi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ...util.param import N_BYTES_PROGRAM_COUNTER
from ..instruction import Instruction, Transition
from ..opcode import Opcode
Expand Down
3 changes: 1 addition & 2 deletions src/zkevm_specs/evm/execution/memory_copy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ...util import FQ, N_BYTES_MEMORY_SIZE
from ..execution_state import ExecutionState
from ..instruction import Instruction, Transition
Expand All @@ -17,8 +18,6 @@ def copy_to_memory(instruction: Instruction):
instruction, MAX_COPY_BYTES, aux.src_addr, aux.src_addr_end, aux.bytes_left
)

data = []
rw_counter_delta = 0
for i in range(MAX_COPY_BYTES):
if not buffer_reader.read_flag(i):
byte = FQ.zero()
Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/push.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..opcode import Opcode

Expand Down
1 change: 1 addition & 0 deletions src/zkevm_specs/evm/execution/selfbalance.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
from ..instruction import Instruction, Transition
from ..table import AccountFieldTag, CallContextFieldTag
from ..opcode import Opcode
Expand Down
6 changes: 4 additions & 2 deletions src/zkevm_specs/evm/execution/slt_sgt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Sequence, Tuple
# type: ignore

from zkevm_specs.util import FQ

from ..instruction import Instruction, Transition
from ..opcode import Opcode
Expand All @@ -7,7 +9,7 @@
def scmp(instruction: Instruction):
opcode = instruction.opcode_lookup(True)

is_sgt, _ = instruction.pair_select(opcode, Opcode.SGT, Opcode.SLT)
is_sgt, _ = instruction.pair_select(opcode, FQ(Opcode.SGT.value), FQ(Opcode.SLT.value))

a = instruction.stack_pop()
b = instruction.stack_pop()
Expand Down
Loading