Skip to content

Commit 9253c7a

Browse files
authored
docs(log): introduce example and benchmark (#128)
* docs(highlight): support python in mdbook * chore(zink): bump version to v0.1.3 * docs(log): introduce example * docs(log): introduce benchmarks * chore(compiler): remove oudated tests
1 parent d0a7535 commit 9253c7a

File tree

10 files changed

+222
-55
lines changed

10 files changed

+222
-55
lines changed

.github/workflows/docs.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Docs
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66

77
jobs:
88
deploy:
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup mdBook
1919
uses: peaceiris/actions-mdbook@v1
2020
with:
21-
mdbook-version: 'latest'
21+
mdbook-version: "latest"
2222

2323
- name: Build the book
2424
run: cd docs && mdbook build
@@ -38,7 +38,6 @@ jobs:
3838

3939
- name: Deploy
4040
uses: peaceiris/actions-gh-pages@v3
41-
# if: github.ref == 'refs/heads/main'
4241
with:
4342
github_token: ${{ secrets.GITHUB_TOKEN }}
4443
publish_dir: ./docs/book

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.log
22
**/*target
33
docs/book
4+
.DS_Store

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "0.1.2"
2+
version = "0.1.3"
33
authors = ["clearloop"]
44
edition = "2021"
55
license = "GPL-3.0-only"
@@ -42,12 +42,12 @@ wasmparser = "0.107.0"
4242
wat = "1.0.66"
4343

4444
# Local Dependencies.
45-
zinkup = { path = "cli", version = "=0.1.2" }
45+
zinkup = { path = "cli", version = "=0.1.3" }
4646
opcodes = { package = "evm-opcodes", path = "codegen/opcodes", version = "=0.0.3", features = ["data"] }
47-
zingen = { path = "codegen", version = "=0.1.2" }
48-
zinkc = { path = "compiler", version = "=0.1.2" }
49-
zink = { path = "zink", version = "=0.1.2" }
50-
zint = { path = "zint", version = "=0.1.2" }
47+
zingen = { path = "codegen", version = "=0.1.3" }
48+
zinkc = { path = "compiler", version = "=0.1.3" }
49+
zink = { path = "zink", version = "=0.1.3" }
50+
zint = { path = "zint", version = "=0.1.3" }
5151

5252
[profile]
5353
dev = { panic = "abort"}

docs/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Examples](./examples/README.md)
88
- [AddTwo](./examples/add-two.md)
99
- [Fibonacci](./examples/fibonacci.md)
10+
- [Log](./examples/log.md)
1011
- [Select](./examples/select.md)
1112
- [Storage](./examples/storage.md)
1213
- [Command Line Tool](./cli/README.md)
@@ -24,6 +25,7 @@
2425
- [Security](./security.md)
2526
- [Benchmarks](./benchmarks/README.md)
2627
- [Fibonacci](./benchmarks/fibonacci.md)
28+
- [Log](./benchmarks/log.md)
2729
- [Storage](./benchmarks/storage.md)
2830
- [Contributing](./contributing/README.md)
2931
- [Architecture](./contributing/architecture.md)

docs/benchmarks/log.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Log
2+
3+
Zink only supports static byte array for log arguments for now, see issue
4+
[#129][#129] for more details.
5+
6+
7+
| ------------ | ---- | ----------- | --------------- |
8+
| Gas Cost | 1031 | 2777 | 2894 |
9+
| Runtime Code | 42 | 632 | 774 |
10+
11+
## `zink`
12+
13+
```rust
14+
//! Addition example.
15+
#![no_std]
16+
17+
// for the panic handler.
18+
#[cfg(not(test))]
19+
extern crate zink;
20+
21+
use zink::Event;
22+
23+
/// A `Ping` event.
24+
///
25+
/// TODO: generate this with proc-macro.
26+
struct Ping;
27+
28+
/// TODO: generate this with proc-macro.
29+
impl Event for Ping {
30+
const NAME: &'static [u8] = b"Ping";
31+
}
32+
33+
#[no_mangle]
34+
pub extern "C" fn log1() {
35+
Ping.log1(b"pong");
36+
}
37+
```
38+
39+
```
40+
63706f6e676350696e6760005260206000a15f5ff3
41+
```
42+
43+
## `vyper`
44+
45+
```python
46+
event Ping:
47+
name: String[4]
48+
topic1: String[4]
49+
50+
@external
51+
def l():
52+
log Ping("Ping", "pong")
53+
```
54+
55+
```
56+
6003361161000c57610127565b5f3560e01c3461012b5763ece866b98118610125577fcf8d08d4ab9d61004e3c20715af5b44c3badc3d3f41ddccbedbef447355ebff460408060c05260046040527f50696e670000000000000000000000000000000000000000000000000000000060605260408160c00181516020830160208301815181525050808252508051806020830101601f825f03163682375050601f19601f8251602001011690509050810190508060e05260046080527f706f6e670000000000000000000000000000000000000000000000000000000060a05260808160c00181516020830160208301815181525050808252508051806020830101601f825f03163682375050601f19601f82516020010116905090508101905060c0a1005b505b5f5ffd5b5f80fda165767970657283000309000b
57+
```
58+
59+
## `solidity`
60+
61+
```sol
62+
// SPDX-License-Identifier: MIT
63+
pragma solidity >=0.7.0 <0.9.0;
64+
65+
contract Test {
66+
event Ping(string name, string topic);
67+
68+
function l() public {
69+
emit Ping("Ping", "pong");
70+
}
71+
}
72+
```
73+
74+
```
75+
608060405234801561001057600080fd5b506004361061002b5760003560e01c8063ece866b914610030575b600080fd5b61003861003a565b005b7fcf8d08d4ab9d61004e3c20715af5b44c3badc3d3f41ddccbedbef447355ebff46040516100679061011a565b60405180910390a1565b600082825260208201905092915050565b7f50696e6700000000000000000000000000000000000000000000000000000000600082015250565b60006100b8600483610071565b91506100c382610082565b602082019050919050565b7f706f6e6700000000000000000000000000000000000000000000000000000000600082015250565b6000610104600483610071565b915061010f826100ce565b602082019050919050565b60006040820190508181036000830152610133816100ab565b90508181036020830152610146816100f7565b905091905056fea26469706673582212201af2a7b1c1d4743d1d089d3eaa1bbd6ecb4186fc95a43320108b18882d7a6dfc64736f6c63430008120033
76+
```
77+
78+
[#129]: https://github.com/zink-lang/zink/issues/129

docs/benchmarks/storage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ selector!
77

88
### Gas Cost
99

10-
11-
| --- | ----- | ----------- | --------------- |
12-
| 42 | 22237 | 22345 | 27738 |
10+
11+
| ----- | ----------- | --------------- |
12+
| 22237 | 22345 | 27738 |
1313

1414
The gas costs here are measured by `transaction cost` + `execution cost`,
1515
for example, the transaction of this function in solidity is `24120`, and

docs/examples/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
This chapter provides various zink examples in rust:
44

5-
| name | knowledges | description |
6-
|--------------------------|--------------------------------------------|---------------------------------------------------|
7-
| [`add-two`][add-two] | `params` | basic program in zink |
8-
| [`if-else`][if-else] | `params`, `code-section` | program with extra instruction `select` from WASM |
9-
| [`fibonacci`][fibonacci] | `params`, `calls`, `recursion`, `if-block` | recursion implementation |
5+
| name | knowledges | description |
6+
| ------------------------ | -------------------------------- | ------------------------------------------------- |
7+
| [`add-two`][add-two] | `params` | basic program in zink |
8+
| [`fibonacci`][fibonacci] | `calls`, `recursion`, `if-block` | recursion implementation |
9+
| [`log`][log] | `log` | log APIs |
10+
| [`select`][select] | `wasm built-in functions` | program with extra instruction `select` from WASM |
11+
| [`storage`][storage] | `storage` | storage operations |
1012

1113
[add-two]: /examples/add-two.md
12-
[if-else]: /examples/if-else.md
1314
[fibonacci]: /examples/fibonacci.md
15+
[log]: /examples/log.md
16+
[select]: /examples/select.md
17+
[storage]: /examples/storage.md

docs/examples/log.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Log
2+
3+
```rust
4+
//! Addition example.
5+
#![no_std]
6+
7+
// for the panic handler.
8+
#[cfg(not(test))]
9+
extern crate zink;
10+
11+
use zink::Event;
12+
13+
/// A `Ping` event.
14+
///
15+
/// TODO: generate this with proc-macro.
16+
struct Ping;
17+
18+
/// TODO: generate this with proc-macro.
19+
impl Event for Ping {
20+
const NAME: &'static [u8] = b"Ping";
21+
}
22+
23+
#[no_mangle]
24+
pub extern "C" fn log1() {
25+
Ping.log1(b"pong");
26+
}
27+
```
28+
29+
The log API of zink is derived by the trait `Event` which provides methods
30+
`log0`, `log1`, `log2`, `log3`, `log4`. We current only supports static
31+
bytes in this API.
32+
33+
```wasm
34+
(module
35+
(type (;0;) (func))
36+
(type (;1;) (func (param i32 i32 i32 i32)))
37+
(import "evm" "log1" (func (;1;) (type 1)))
38+
(import "env" "memory" (memory (;0;) 17))
39+
(func (;1;) (type 0)
40+
i32.const 1048576
41+
i32.const 4
42+
i32.const 1048580
43+
i32.const 4
44+
call 0)
45+
(export "log1" (func 1))
46+
(data (;0;) (i32.const 1048576) "Pingpong"))
47+
```
48+
49+
The static byte array will be compiled to the data section of wasm, `zinkc`
50+
gets it from the data section then process it to the logging interfaces.
51+
52+
```
53+
63706f6e676350696e6760005260206000a15f5ff3
54+
```

docs/theme/highlight.js

Lines changed: 61 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)