-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
10 changed files
with
222 additions
and
55 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.log | ||
**/*target | ||
docs/book | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,78 @@ | ||
# Log | ||
|
||
Zink only supports static byte array for log arguments for now, see issue | ||
[#129][#129] for more details. | ||
|
||
| | Zink | [email protected] | [email protected] | | ||
| ------------ | ---- | ----------- | --------------- | | ||
| Gas Cost | 1031 | 2777 | 2894 | | ||
| Runtime Code | 42 | 632 | 774 | | ||
|
||
## `zink` | ||
|
||
```rust | ||
//! Addition example. | ||
#![no_std] | ||
|
||
// for the panic handler. | ||
#[cfg(not(test))] | ||
extern crate zink; | ||
|
||
use zink::Event; | ||
|
||
/// A `Ping` event. | ||
/// | ||
/// TODO: generate this with proc-macro. | ||
struct Ping; | ||
|
||
/// TODO: generate this with proc-macro. | ||
impl Event for Ping { | ||
const NAME: &'static [u8] = b"Ping"; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn log1() { | ||
Ping.log1(b"pong"); | ||
} | ||
``` | ||
|
||
``` | ||
63706f6e676350696e6760005260206000a15f5ff3 | ||
``` | ||
|
||
## `vyper` | ||
|
||
```python | ||
event Ping: | ||
name: String[4] | ||
topic1: String[4] | ||
|
||
@external | ||
def l(): | ||
log Ping("Ping", "pong") | ||
``` | ||
|
||
``` | ||
6003361161000c57610127565b5f3560e01c3461012b5763ece866b98118610125577fcf8d08d4ab9d61004e3c20715af5b44c3badc3d3f41ddccbedbef447355ebff460408060c05260046040527f50696e670000000000000000000000000000000000000000000000000000000060605260408160c00181516020830160208301815181525050808252508051806020830101601f825f03163682375050601f19601f8251602001011690509050810190508060e05260046080527f706f6e670000000000000000000000000000000000000000000000000000000060a05260808160c00181516020830160208301815181525050808252508051806020830101601f825f03163682375050601f19601f82516020010116905090508101905060c0a1005b505b5f5ffd5b5f80fda165767970657283000309000b | ||
``` | ||
|
||
## `solidity` | ||
|
||
```sol | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.7.0 <0.9.0; | ||
contract Test { | ||
event Ping(string name, string topic); | ||
function l() public { | ||
emit Ping("Ping", "pong"); | ||
} | ||
} | ||
``` | ||
|
||
``` | ||
608060405234801561001057600080fd5b506004361061002b5760003560e01c8063ece866b914610030575b600080fd5b61003861003a565b005b7fcf8d08d4ab9d61004e3c20715af5b44c3badc3d3f41ddccbedbef447355ebff46040516100679061011a565b60405180910390a1565b600082825260208201905092915050565b7f50696e6700000000000000000000000000000000000000000000000000000000600082015250565b60006100b8600483610071565b91506100c382610082565b602082019050919050565b7f706f6e6700000000000000000000000000000000000000000000000000000000600082015250565b6000610104600483610071565b915061010f826100ce565b602082019050919050565b60006040820190508181036000830152610133816100ab565b90508181036020830152610146816100f7565b905091905056fea26469706673582212201af2a7b1c1d4743d1d089d3eaa1bbd6ecb4186fc95a43320108b18882d7a6dfc64736f6c63430008120033 | ||
``` | ||
|
||
[#129]: https://github.com/zink-lang/zink/issues/129 |
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 |
---|---|---|
|
@@ -7,9 +7,9 @@ selector! | |
|
||
### Gas Cost | ||
|
||
| io | Zink | [email protected] | [email protected] | | ||
| --- | ----- | ----------- | --------------- | | ||
| 42 | 22237 | 22345 | 27738 | | ||
| Zink | [email protected] | [email protected] | | ||
| ----- | ----------- | --------------- | | ||
| 22237 | 22345 | 27738 | | ||
|
||
The gas costs here are measured by `transaction cost` + `execution cost`, | ||
for example, the transaction of this function in solidity is `24120`, and | ||
|
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,54 @@ | ||
# Log | ||
|
||
```rust | ||
//! Addition example. | ||
#![no_std] | ||
|
||
// for the panic handler. | ||
#[cfg(not(test))] | ||
extern crate zink; | ||
|
||
use zink::Event; | ||
|
||
/// A `Ping` event. | ||
/// | ||
/// TODO: generate this with proc-macro. | ||
struct Ping; | ||
|
||
/// TODO: generate this with proc-macro. | ||
impl Event for Ping { | ||
const NAME: &'static [u8] = b"Ping"; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn log1() { | ||
Ping.log1(b"pong"); | ||
} | ||
``` | ||
|
||
The log API of zink is derived by the trait `Event` which provides methods | ||
`log0`, `log1`, `log2`, `log3`, `log4`. We current only supports static | ||
bytes in this API. | ||
|
||
```wasm | ||
(module | ||
(type (;0;) (func)) | ||
(type (;1;) (func (param i32 i32 i32 i32))) | ||
(import "evm" "log1" (func (;1;) (type 1))) | ||
(import "env" "memory" (memory (;0;) 17)) | ||
(func (;1;) (type 0) | ||
i32.const 1048576 | ||
i32.const 4 | ||
i32.const 1048580 | ||
i32.const 4 | ||
call 0) | ||
(export "log1" (func 1)) | ||
(data (;0;) (i32.const 1048576) "Pingpong")) | ||
``` | ||
|
||
The static byte array will be compiled to the data section of wasm, `zinkc` | ||
gets it from the data section then process it to the logging interfaces. | ||
|
||
``` | ||
63706f6e676350696e6760005260206000a15f5ff3 | ||
``` |
Large diffs are not rendered by default.
Oops, something went wrong.