-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/eels-stack' into feat/memory
- Loading branch information
Showing
15 changed files
with
305 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,18 @@ | |
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml | ||
version: 0.1 | ||
cli: | ||
version: 1.22.7 | ||
version: 1.22.8 | ||
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins) | ||
plugins: | ||
sources: | ||
- id: trunk | ||
ref: v1.6.4 | ||
ref: v1.6.6 | ||
uri: https://github.com/trunk-io/plugins | ||
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes) | ||
runtimes: | ||
enabled: | ||
- [email protected] | ||
- node@18.12.1 | ||
- node@18.20.5 | ||
- [email protected] | ||
downloads: | ||
- name: rust | ||
|
@@ -61,28 +61,28 @@ lint: | |
read_output_from: stdout | ||
run_linter_from: workspace | ||
enabled: | ||
- cspell@8.15.4 | ||
- cspell@8.17.1 | ||
- [email protected] | ||
- [email protected].3 | ||
- [email protected].4 | ||
- [email protected] | ||
- cairo@SYSTEM | ||
- rustfmt@2024-10-31 | ||
- clippy@2024-10-31 | ||
- [email protected].269 | ||
- rustfmt@1.65.0 | ||
- clippy@1.65.0 | ||
- [email protected].342 | ||
- git-diff-check | ||
- [email protected].0 | ||
- [email protected].1-beta | ||
- [email protected] | ||
- markdownlint@0.42.0 | ||
- [email protected].0 | ||
- [email protected].2 | ||
- prettier@3.3.3 | ||
- ruff@0.7.1 | ||
- markdownlint@0.43.0 | ||
- [email protected].2 | ||
- [email protected].3 | ||
- prettier@3.4.2 | ||
- ruff@0.8.3 | ||
- [email protected] | ||
- [email protected] | ||
- solidity@SYSTEM | ||
- [email protected] | ||
- trivy@0.56.2 | ||
- trufflehog@3.82.13 | ||
- trivy@0.58.0 | ||
- trufflehog@3.87.2 | ||
- [email protected] | ||
|
||
actions: | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from ethereum_types.bytes import BytesStruct | ||
|
||
struct StackUnderflowError { | ||
value: BytesStruct*, | ||
} | ||
|
||
struct StackOverflowError { | ||
value: BytesStruct*, | ||
} |
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,64 @@ | ||
from ethereum_types.numeric import U256, U256Struct | ||
from ethereum_types.bytes import BytesStruct | ||
from starkware.cairo.common.dict import DictAccess, dict_read, dict_write | ||
from ethereum.cancun.vm.exceptions import StackOverflowError, StackUnderflowError | ||
|
||
struct Stack { | ||
value: StackStruct*, | ||
} | ||
|
||
struct StackStruct { | ||
dict_ptr_start: StackDictAccess*, | ||
dict_ptr: StackDictAccess*, | ||
len: felt, | ||
} | ||
|
||
struct StackDictAccess { | ||
key: felt, | ||
prev_value: U256, | ||
new_value: U256, | ||
} | ||
|
||
const STACK_MAX_SIZE = 1024; | ||
|
||
func pop{stack: Stack}() -> (U256, StackUnderflowError) { | ||
alloc_locals; | ||
let len = stack.value.len; | ||
if (len == 0) { | ||
tempvar err = StackUnderflowError(new BytesStruct(cast(0, felt*), 0)); | ||
let val = U256(cast(0, U256Struct*)); | ||
return (val, err); | ||
} | ||
|
||
let dict_ptr = cast(stack.value.dict_ptr, DictAccess*); | ||
with dict_ptr { | ||
let (pointer) = dict_read(len - 1); | ||
} | ||
let new_dict_ptr = cast(dict_ptr, StackDictAccess*); | ||
|
||
tempvar stack = Stack(new StackStruct(stack.value.dict_ptr_start, new_dict_ptr, len - 1)); | ||
tempvar value = U256(cast(pointer, U256Struct*)); | ||
|
||
let ok_ = StackUnderflowError(cast(0, BytesStruct*)); | ||
return (value, ok_); | ||
} | ||
|
||
func push{stack: Stack}(value: U256) -> StackOverflowError { | ||
alloc_locals; | ||
let len = stack.value.len; | ||
if (len == STACK_MAX_SIZE) { | ||
tempvar err = StackOverflowError(new BytesStruct(cast(0, felt*), 0)); | ||
return err; | ||
} | ||
|
||
let dict_ptr = cast(stack.value.dict_ptr, DictAccess*); | ||
with dict_ptr { | ||
dict_write(len, cast(value.value, felt)); | ||
} | ||
let new_dict_ptr = cast(dict_ptr, StackDictAccess*); | ||
|
||
tempvar stack = Stack(new StackStruct(stack.value.dict_ptr_start, new_dict_ptr, len + 1)); | ||
let ok_ = StackOverflowError(cast(0, BytesStruct*)); | ||
|
||
return ok_; | ||
} |
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
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,40 @@ | ||
from typing import List | ||
|
||
import pytest | ||
from ethereum_types.numeric import U256 | ||
from hypothesis import assume, given | ||
|
||
from ethereum.cancun.vm.exceptions import StackOverflowError, StackUnderflowError | ||
from ethereum.cancun.vm.stack import pop, push | ||
|
||
|
||
class TestStack: | ||
def test_pop_underflow(self, cairo_run): | ||
stack = [] | ||
with pytest.raises(StackUnderflowError): | ||
cairo_run("pop", stack) | ||
with pytest.raises(StackUnderflowError): | ||
pop(stack) | ||
|
||
@given(stack=...) | ||
def test_pop_success(self, cairo_run, stack: List[U256]): | ||
assume(len(stack) > 0) | ||
|
||
(new_stack_cairo, popped_value_cairo) = cairo_run("pop", stack) | ||
popped_value_py = pop(stack) | ||
assert new_stack_cairo == stack | ||
assert popped_value_cairo == popped_value_py | ||
|
||
@given(value=...) | ||
def test_push_overflow(self, cairo_run, value: U256): | ||
stack = [U256(0)] * 1024 | ||
with pytest.raises(StackOverflowError): | ||
cairo_run("push", stack, value) | ||
with pytest.raises(StackOverflowError): | ||
push(stack, value) | ||
|
||
@given(stack=..., value=...) | ||
def test_push_success(self, cairo_run, stack: List[U256], value: U256): | ||
new_stack_cairo = cairo_run("push", stack, value) | ||
push(stack, value) | ||
assert new_stack_cairo == stack |
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
Oops, something went wrong.