Skip to content

Commit

Permalink
Merge pull request #1 from gzanitti/hardfork_selection
Browse files Browse the repository at this point in the history
Hardfork selection
  • Loading branch information
gzanitti authored Apr 20, 2024
2 parents de5d96b + 86076d2 commit b66401b
Show file tree
Hide file tree
Showing 29 changed files with 850 additions and 412 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/src/ch02-lang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This example should increment a value from 0 to 255 on the stack, then halt exec

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push1 0x00
Expand All @@ -28,7 +29,7 @@ loop:
pop
stop # This halts execution
# "#;
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new());
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new(), etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
```

Expand Down
14 changes: 9 additions & 5 deletions doc/src/ch02-lang/ch02-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ While an assembled `push` must have a concrete value, it is often useful when de

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push1 1+(2*3)/4
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x02]);
```

## Definition

An **expression** is a standard infix mathematical expression that is evaluated during assembly. Its computed value *must* fit within the preceding `push`'s size allowance (eg. less than 256 for `push8`).
An **expression** is a standard infix mathematical expression that is evaluated during assembly. Its computed value _must_ fit within the preceding `push`'s size allowance (eg. less than 256 for `push8`).

### Terms

Expand Down Expand Up @@ -50,12 +51,13 @@ A [label](ch03-labels.md) may be used as a term in an expression.

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
start:
push1 start + 1
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x01]);
```
Expand All @@ -66,11 +68,12 @@ start:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push4 selector("transfer(uint256,uint256)")
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x63, 12, 247, 158, 10]);
```
Expand All @@ -83,6 +86,7 @@ Expressions support the following binary operators:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push1 1+2 # addition
push1 1*2 # multiplication
Expand All @@ -91,7 +95,7 @@ push1 2/2 # division
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x03, 0x60, 0x02, 0x60, 0x01, 0x60, 0x01]);
```
6 changes: 4 additions & 2 deletions doc/src/ch02-lang/ch03-labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Manually counting out jump destination addresses would be a monumentally pointle

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
label0: # <- This is a label called "label0",
## and it has the value 0, since it is
Expand All @@ -16,7 +17,7 @@ label0: # <- This is a label called "label0",
jump # Now we jump to zero, which is a
## `jumpdest` instruction, looping forever.
# "#;
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new());
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new(), etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
```

Expand All @@ -34,6 +35,7 @@ That's not all! You can also use labels to calculate lengths:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push1 start
push1 end
Expand All @@ -46,7 +48,7 @@ start:
pc
end:
# "#;
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new());
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new(), etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
```

Expand Down
7 changes: 4 additions & 3 deletions doc/src/ch02-lang/ch04-macros/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ An instruction macro looks like this:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
%macro push_sum(a, b)
push1 $a + $b
Expand All @@ -20,7 +21,7 @@ An instruction macro looks like this:
%push_sum(4, 2)
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x06]);
```
Expand All @@ -37,6 +38,7 @@ Expression macros _do not_ begin with `%`, and cannot replace instructions. Inst

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
%def add_one(num)
$num+1
Expand All @@ -45,7 +47,7 @@ Expression macros _do not_ begin with `%`, and cannot replace instructions. Inst
push1 add_one(41)
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x2a]);
```
Expand All @@ -55,4 +57,3 @@ Here, `add_one(...)` is an expression macro that returns the `num+1`. The fully
```ignore
push1 42
```

13 changes: 8 additions & 5 deletions doc/src/ch02-lang/ch04-macros/ch01-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ stop

The `%include` macro expands to the instructions read from another file, but unlike `%import`, the included file is assembled independently from the current file:

- Labels from the included file are _not_ available in the including file, and vise versa.
- The address of the first instruction in the included file will be zero.
- Labels from the included file are _not_ available in the including file, and vise versa.
- The address of the first instruction in the included file will be zero.

The path is resolved relative to the current file.

Expand Down Expand Up @@ -79,14 +79,15 @@ For example:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
%push(hello)
hello:
jumpdest
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x02, 0x5b]);
```
Expand All @@ -108,11 +109,12 @@ For example:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push4 selector("transfer(address,uint256)") # <- expands to 0x63a9059cbb
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x63, 0xa9, 0x05, 0x9c, 0xbb]);
```
Expand All @@ -131,11 +133,12 @@ For example:

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
push32 topic("transfer(address,uint256)")
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x7f, 169, 5, 156, 187, 42, 176, 158, 178, 25, 88, 63, 74, 89, 165, 208, 98, 58, 222, 52, 109, 150, 43, 205, 78, 70, 177, 29, 160, 71, 201, 4, 155]);
```
Expand Down
6 changes: 4 additions & 2 deletions doc/src/ch02-lang/ch04-macros/ch02-expression.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Expression macros can accept an arbitrary number of parameters. Parameters are r

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
%def my_macro()
42
Expand All @@ -17,7 +18,7 @@ Expression macros can accept an arbitrary number of parameters. Parameters are r
$x+$y+$z
%end
# "#;
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new());
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new(), etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
```

Expand All @@ -27,6 +28,7 @@ Expression macros can be invoked anywhere an expression is expected.

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
# %def my_macro()
# 42
Expand All @@ -38,7 +40,7 @@ push1 my_macro()
push1 sum(1, 2, my_macro())
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x2a, 0x60, 0x2d]);
```
6 changes: 4 additions & 2 deletions doc/src/ch02-lang/ch04-macros/ch03-instruction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Instruction macros can accept an arbitrary number of parameters. Parameters are

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
%macro my_macro()
push1 42
Expand All @@ -17,7 +18,7 @@ Instruction macros can accept an arbitrary number of parameters. Parameters are
push1 $x+$y+$z
%end
# "#;
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new());
# let mut ingest = etk_asm::ingest::Ingest::new(Vec::new(), etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
```

Expand All @@ -27,6 +28,7 @@ Expression macros can be invoked anywhere an instruction is expected.

```rust
# extern crate etk_asm;
# extern crate etk_ops;
# let src = r#"
# %macro my_macro()
# push1 42
Expand All @@ -38,7 +40,7 @@ Expression macros can be invoked anywhere an instruction is expected.
%sum(1, 2, 3)
# "#;
# let mut output = Vec::new();
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output);
# let mut ingest = etk_asm::ingest::Ingest::new(&mut output, etk_ops::HardFork::Cancun);
# ingest.ingest(file!(), src).unwrap();
# assert_eq!(output, &[0x60, 0x2a, 0x60, 0x06]);
```
12 changes: 10 additions & 2 deletions etk-analyze/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
name = "etk-analyze"
version = "0.4.0-dev"
edition = "2018"
authors = ["Sam Wilson <[email protected]>", "lightclient <[email protected]>"]
authors = [
"Sam Wilson <[email protected]>",
"lightclient <[email protected]>",
]
license = "MIT OR Apache-2.0"
description = "EVM Toolkit analysis tools"
homepage = "https://quilt.github.io/etk"
repository = "https://github.com/quilt/etk"
readme = "README.md"
keywords = ["etk", "ethereum"]
categories = ["cryptography::cryptocurrencies", "command-line-utilities", "development-tools"]
categories = [
"cryptography::cryptocurrencies",
"command-line-utilities",
"development-tools",
]

[features]
cli = ["etk-cli", "etk-asm", "clap", "snafu"]
Expand All @@ -20,6 +27,7 @@ clap = { optional = true, version = "3.1", features = ["derive"] }
etk-cli = { optional = true, path = "../etk-cli", version = "0.4.0-dev" }
etk-asm = { optional = true, path = "../etk-asm", version = "0.4.0-dev" }
etk-dasm = { path = "../etk-dasm", version = "0.4.0-dev" }
etk-ops = { path = "../etk-ops", version = "0.4.0-dev" }
z3 = { version = "0.11.2", features = ["static-link-z3"] }

[dependencies.petgraph]
Expand Down
3 changes: 2 additions & 1 deletion etk-analyze/src/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ mod tests {

use etk_asm::disasm::Disassembler;
use etk_asm::ingest::Ingest;
use etk_ops::HardFork;

use etk_dasm::blocks::basic::Separator;

Expand Down Expand Up @@ -328,7 +329,7 @@ mod tests {
{
fn compile(&self) -> Disassembler {
let mut output = Disassembler::new();
Ingest::new(&mut output)
Ingest::new(&mut output, HardFork::Cancun)
.ingest("./test", self.source)
.unwrap();
output
Expand Down
Loading

0 comments on commit b66401b

Please sign in to comment.