Skip to content

Instantly share code, notes, and snippets.

@seunlanlege
seunlanlege / multi_merkle_proof.rs
Last active January 9, 2023 17:14
Algorithm to calculate the root hash given a merkle multi proof
pub fn calculate_root(proof: Vec<Vec<(usize, [u8; 32])>>) -> [u8; 32] {
let mut previous_layer = vec![];
for layer in proof {
let mut current_layer = vec![];
if previous_layer.len() == 0 {
current_layer = layer;
} else {
current_layer.extend(previous_layer.drain(..));
current_layer.extend(&layer);
current_layer.sort_by(|(a_i, _), (b_i, _)| a_i.cmp(b_i));
substrate on  seun-remove-client-sc-network [$] via 𝗥 v1.41.0
➜ env RUST_LOG=trie=info,trace cargo test -p sc-network --lib protocol::light_client_handler::tests::send_receive_header
Finished test [unoptimized + debuginfo] target(s) in 0.86s
Running target/debug/deps/sc_network-bbd6be5835037894
running 1 test
[2020-03-12T10:29:24Z TRACE sc_state_db] StateDb settings: Constrained(Constraints { max_blocks: Some(4294967295), max_mem: None })
[2020-03-12T10:29:24Z TRACE sc_state_db] DB pruning mode: None
[2020-03-12T10:29:24Z TRACE sc_state_db::pruning] Reading pruning journal. Pending #0
[2020-03-12T10:29:24Z INFO sc_client::client] Initializing Genesis block/state (state: 0x360a…7800, header-hash: 0xa2ca…a899)
@seunlanlege
seunlanlege / f.rs
Created September 2, 2019 15:59
Rust impl of blake2 compression function
const SIGMA: [[usize; 16]; 10] = [
[0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15],
[14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3],
[11, 12, 5, 15, 8, 0, 2, 13, 10, 3, 7, 9, 14, 6, 1, 4],
[7, 3, 13, 11, 9, 1, 12, 14, 2, 5, 4, 15, 6, 10, 0, 8],
[9, 5, 2, 10, 0, 7, 4, 15, 14, 11, 6, 3, 1, 12, 8, 13],
[2, 6, 0, 8, 12, 10, 11, 3, 4, 7, 15, 1, 13, 5, 14, 9],
[12, 1, 14, 4, 5, 15, 13, 10, 0, 6, 9, 8, 7, 3, 2, 11],
[13, 7, 12, 3, 11, 14, 1, 9, 5, 15, 8, 2, 0, 4, 6, 10],

Keybase proof

I hereby claim:

  • I am seunlanlege on github.
  • I am seunlanlege (https://keybase.io/seunlanlege) on keybase.
  • I have a public key ASCHC6anyUcXE80_vYpHGIVxjkp4NKcYzVH3R70i1glJoQo

To claim this, I am signing this object:

@seunlanlege
seunlanlege / tsconfig.json
Created July 1, 2018 08:42
tsconfig for react-native projects
{
"compilerOptions": {
"target": "es2017",
"moduleResolution": "node",
"jsx": "react-native",
"noEmit": false,
"outDir": "outputs",
"sourceMap": true,
"allowSyntheticDefaultImports": true,
"preserveConstEnums": true,
@seunlanlege
seunlanlege / README.md
Created May 20, 2018 14:06 — forked from qti3e/README.md
List of file signatures and mime types based on file extensions
@seunlanlege
seunlanlege / compute.js
Created February 28, 2018 12:28
A script to compute the total amount you've spent on uber rides.
/*
you'll need to run `yarn add axios cheerio` to add the dependencies
then `node compute.js`
*/
const axios = require("axios")
const fs = require("fs")
const cheerio = require("cheerio")
async function main() {
let sum = 0
// Place your settings in this file to overwrite the default settings
{
"swift.path.swift_driver_bin": "/usr/bin/swift/bin/swift",
"files.associations": {
// "extension name": "html",
".jsx": "html"
},
"rust.rls": {
"executable": "rustup",
"args": ["run", "nightly", "rls"]
import {observable, transaction, createTransformer} from 'mobx';
import Box from './box';
import {randomUuid} from '../utils';
/*
The store that holds our domain: boxes and arrows
*/
const store = observable({
boxes: [],