Skip to content

Instantly share code, notes, and snippets.

@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
########## BAD BLOCK #########
Chain config: {ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}
Number: 5708548
Hash: 0xa382e502e982ee89d300f839b61a38209f702f24ad1696056c2a9d2d97e43a07
&{[] 1 21000 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [] [191 119 99 221 143 139 143 177 235 233 157 219 136 52 21 78 94 26 159 20 149 39 239 118 179 155 210 78 73 104 25 92] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] 21000}
&{[] 1 42000 [0 0 0 0 0
@chfast
chfast / loader.html
Created May 22, 2018 11:38
WASM browser loader
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<h1>WASM loader</h1>
<pre id="log">Log:
</pre>
<script>
log = document.getElementById('log');