Skip to content

Instantly share code, notes, and snippets.

@s1na
s1na / ipfs-cluster-test-races.log
Created April 24, 2018 13:20
ipfs-cluster races happening during tests
==================
WARNING: DATA RACE
Read at 0x00c4204329f0 by goroutine 33:
github.com/ipfs/ipfs-cluster/consensus/raft.(*Consensus).finishBootstrap()
/go/src/github.com/ipfs/ipfs-cluster/consensus/raft/consensus.go:119 +0x123
Previous write at 0x00c4204329f0 by goroutine 18:
github.com/ipfs/ipfs-cluster/consensus/raft.(*Consensus).SetClient()
/go/src/github.com/ipfs/ipfs-cluster/consensus/raft/consensus.go:179 +0x48
github.com/ipfs/ipfs-cluster.(*Cluster).setupRPCClients()
@s1na
s1na / zos-lib-node-9-err
Created July 8, 2018 08:34
Error logs for npm install with npm v5.10
npm ERR! path /data/home/s1na/dev/eth/zos-lib/examples/complex/node_modules/.staging/zos-lib-5f365ef1/node_modules/@mrmlnc/readdir-enhanced
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/data/home/s1na/dev/eth/zos-lib/examples/complex/node_modules/.staging/zos-lib-5f365ef1/node_modules/@mrmlnc/readdir-enhanced' -> '/data/home/s1na/dev/eth/zos-lib/examples/complex/node_modules/.staging/@mrmlnc/readdir-enhanced-ff250cb7'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
@s1na
s1na / ethereumjs-vm-perf.md
Last active January 10, 2019 09:22
Profiling EthereumJS VM

As a first step to profile ethereumjs-vm, I used clinic on a couple of existing tests. To get a flamegraph of the blockchain tests, run:

NODE_OPTIONS="--max-old-space-size=4096" clinic flame -- node ./tests/tester.js -b --excludeDir='GeneralStateTests'

The image in this gist is the result of running this command on my personal computer.

@s1na
s1na / README.md
Last active March 11, 2019 10:16
Modexp reduction benchmark

MODEXP reduction benchmark

State tests were executed and execution time of the expmod(B, E, M) instruction in the MODEXP precompile were measured for master and the PR which uses BN.red for computing MODEXP.

The measurements are in millisecond, and they've been sorted to give an idea of generally how long the two approaches take. Corresponding lines in the two files do not necessarily represent the same modexp operation.

@s1na
s1na / index.js
Created May 17, 2019 09:41
keccak256 wasm
const fs = require('fs')
const path = require('path')
const memset = (mem, data, offset) => {
const asBytes = new Uint8Array(mem.buffer, offset, data.length)
asBytes.set(data)
}
const memget = (mem, offset, length) => {
return Buffer.from(new Uint8Array(mem.buffer, offset, length))
@s1na
s1na / README.md
Created June 4, 2019 12:43
Hello world scout script in assemblyscript

A simple scout script which simply increments the last byte of the pre state root, and saves that as post state root.

Build

Install assemblyscript:

npm i -D AssemblyScript/assemblyscript
@s1na
s1na / Cargo.toml
Created June 14, 2019 14:28
ZoKrates -> scout stateless script
[package]
name = "zkmul"
version = "0.0.0"
license = "Apache-2.0"
repository = "https://github.com/ewasm/scout"
description = "zero knowledge multiplication"
publish = false
edition = "2018"
[lib]
@s1na
s1na / smpt-relayer.js
Created July 2, 2019 12:40
Relayer for stateless MPT-like token (scout script)
const assert = require('assert')
const { promisify } = require('util')
const BN = require('bn.js')
const Trie = require('merkle-patricia-tree')
const Account = require('ethereumjs-account').default
const StateManager = require('ethereumjs-vm/dist/state/stateManager').default
const PStateManager = require('ethereumjs-vm/dist/state/promisified').default
const { keccak256, ecsign, stripZeros } = require('ethereumjs-util')
const { encode } = require('rlp')
@s1na
s1na / README.md
Created August 7, 2019 15:02
Refreshing stale MPT proofs

Background

In the context of stateless execution, a node does not need to store the full state of the blockchain and expects each transaction to come with all the necessary parts of the state and proofs for the validity of those parts.

The responsibility of attaching the proofs falls on the transaction sender or a third party who's storing the necessary parts of the trie. If a transaction doesn't make it immediately into the next block, the blockchain advances forward, modifying the state (and the state root). This causes all the proofs that were generated against a previous state root to become stale.

Simulation

This script simulates the following scenario:

@s1na
s1na / ee.ts
Last active September 18, 2019 13:18
Turboproof EE in JS
import * as assert from 'assert'
import BN = require('bn.js')
import { keccak256 } from 'ethereumjs-util'
import { encode, decode } from 'rlp'
import { verifyMultiproof, decodeInstructions } from './multiproof'
interface TestSuite {
preStateRoot: Buffer
blockData: Buffer
}