Skip to content

Instantly share code, notes, and snippets.

View chfast's full-sized avatar

Paweł Bylica chfast

View GitHub Profile
#include <stdint.h>
#include <stdio.h>
#include <time.h>
int32_t interp(unsigned char *code, int initval)
{
int pc = 0;
int32_t val = initval;
while(1) {
switch(code[pc++]) {
@chfast
chfast / keccak.wat
Last active August 16, 2019 17:05
Keccak.wasm
(module
(type (;0;) (func (param i32)))
(type (;1;) (func (param i32 i32 i32) (result i32)))
(type (;2;) (func (param i32 i32 i32)))
(import "env" "memory" (memory (;0;) 256 256))
(func (;0;) (type 0) (param i32)
(local i32 i32 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64)
local.get 0
i64.load
local.set 20
@chfast
chfast / mul768.wat
Last active June 20, 2019 19:57
768-bit multiplication implemented in wasm
;; C ABI: void mul768(uint64_t* product, const uint64_t* a, const uint64_t* b)
(module
(type (;0;) (func (param i32 i32 i32)))
(import "env" "memory" (memory (;0;) 256 256))
(func (;0;) (type 0) (param i32 i32 i32)
(local i32 i32 i32 i32 i32 i32 i64 i64 i64 i64 i64 i64 i64 i64)
i32.const 11
local.set 5
loop ;; label = @1
@chfast
chfast / all_tests.h
Created May 6, 2019 09:05
Covert CMake list into C array of string literals
# Generated file:
const char* allTests[] =
{
"A",
"B",
"C",
"D",
"E",
@chfast
chfast / mul256_analisys.md
Last active April 25, 2019 06:33
Analysis of 256-bit mutiplication implementations in context of wasm

All assembly snippets are generated from intx. Compiled by clang 9 (trung), -O3 -march=skylake.

The first one mul256_x86_64.s is the one evmone is using. It exploits the fact that x86 has mul instruction performing full 64x64 -> 128 multiplication. See umul() procedure in intx. This instruction cannot be used by wasm, but I'm working on teaching LLVM to recognize the 64x64 -> 128 mul pattern.

Instruction count:

@chfast
chfast / 1.log
Last active January 10, 2019 11:46
aleth-bootnode crash logs
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##5e6b68ec…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##0c46d0d2…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##70b28671…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##6028267a…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##85c98043…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##8516b786…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##d693da0f…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##e602ae32…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##24d8ec7d…
DEBUG 01-10 11:11:01 p2p discov p2p.nodes.drop ##0fa9c65d…
l=0 i=0 word=9de9a7a2
l=0 i=1 word=9a96da15
l=0 i=2 word=97848039
l=0 i=3 word=bcde5009
l=1 i=0 word=19173998
l=1 i=1 word=62077d8
l=1 i=2 word=6c596733
l=1 i=3 word=18a6f318
l=2 i=0 word=9c4e4a04
l=2 i=1 word=cdff0add
build/bin/geth --datadir ~/.ethereum/ewasm --networkid=66 --vm.ewasm=/tmp/evmc6/lib/libhera.so:metering=true --bootnodes="$bn1,$bn2" --syncmode=full --vmodule "eth=3,p2p=3" --port 11111
INFO [10-21|19:21:11.840] Maximum peer count ETH=25 LES=0 total=25
INFO [10-21|19:21:11.841] Starting peer-to-peer node instance=Geth/v1.8.18-unstable-895d3601/linux-amd64/go1.11.1
INFO [10-21|19:21:11.841] Allocated cache and file handles database=/home/chfast/.ethereum/ewasm/geth/chaindata cache=768 handles=512
INFO [10-21|19:21:12.000] Initialised chain configuration config="{ChainID: 66 Homestead: 1 DAO: <nil> DAOSupport: false EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 4 Constantinople: <nil> Engine: ethash}"
INFO [10-21|19:21:12.000] Disk storage enabled for ethash caches dir=/home/chfast/.ethereum/ewasm/geth/ethash count=3
INFO [10-21|19:21:12.000] Disk storage enabled for ethash DAGs dir=/home/chfast/.ethash count=2
INF
@chfast
chfast / genesis.json
Last active October 21, 2018 16:36 — forked from jwasinger/genesis.json
Geth testnet genesis with working metering
{
"config": {
"chainId": 66,
"homesteadBlock": 1,
"eip150Block": 2,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 3,
"eip158Block": 3,
"byzantiumBlock": 4,
"ewasmBlock": 0,
@chfast
chfast / ethash1a.md
Created August 26, 2018 21:05
Ethash 1a

Ethash 1a

  1. Define fnv1a() as
    def fnv1a(v1, v2):
        return ((v1 ^ v2) * FNV1A_PRIME) % 2**32
    where FNV1A_PRIME is 16777499 or 16777639.`
  2. Change the hash function that determines the DAG item index in Ethash algorighm from fnv() to new fnv1a(). In Main Loop change