Skip to content

Instantly share code, notes, and snippets.

View pepyakin's full-sized avatar

Sergei Shulepov pepyakin

View GitHub Profile
@pepyakin
pepyakin / risczero-mac-docker.md
Created January 3, 2024 16:05
Multiarch risc0 container builds

We need to have risc0 available in docker containers. Modern macs are aarch64 machines. When you run docker on mac, a aarch64 VM will be used. It's possible to use x86-64, but those would run slower.

Unfortunately, risc0 binaries are not built for aarch64 linux. risc0/risc0#1286

There are two general approaches that I found.

Qemu system emulation

It's possible to use qemu for system emulation. I managed to build both on macOS and on nixOS.

@pepyakin
pepyakin / upgrade.js
Created December 24, 2021 15:17
polkadot.js script for upgrading a parachain
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api'
import { cryptoWaitReady } from '@polkadot/util-crypto'
import { readFileSync } from 'fs';
async function connect(port, types) {
const provider = new WsProvider('ws://127.0.0.1:' + port)
const api = new ApiPromise({ provider, types })
await api.isReady
return api
}
@pepyakin
pepyakin / README.md
Created January 15, 2021 14:48
Run polkadot and cumulus localnet
  1. Build master of polkadot with cargo build --release --features real-overseer
  2. Build master of cumulus with cargo build --release -p rococo-collator
  3. Update the config above so that paths point to proper locations
  4. Take polkadot-launch of d9b6708e5175244aa5c83685aa5d0633b837a1fe (or master should be fine really)
  5. Run with RUST_LOG=parachains_runtime_inclusion=trace,candidate_backing=trace,collation_generation=trace,candidate_selection=trace,runtime=debug npm run start launch-hrmp.json
use std::cell::UnsafeCell;
#[test]
fn evil() {
let array: [u8; 2] = [b'A', b'B'];
let array = UnsafeCell::new(array);
let (_loaded_a, _loaded_b) = unsafe {
let a = &mut *{
let cached_entries = &mut *array.get();
@pepyakin
pepyakin / Dockerfile
Last active March 22, 2022 12:05
Substrate Raspberry PI cross-compile build
# Put this file in the root of substrate / polkadot directory and build the image using
# the following command:
#
# docker build -t <container id> .
#
# you can pick <container id> yourself. For example: `johndoe/rpi-cross`.
#
FROM rust:latest
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.
// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of

When one try to run wasm-reduce on macOS machine, they will see something like this:

wasm-reduce -v -f \
	--timeout=15 \
	--command="./predicate.sh" \
	--test=test.wasm \
	--working=working.wasm \
	~/Downloads/wasm-collection-master/misc-valid/cv-wasm.wasm
(module
(import "proxy" "execute_block"
(func $execute_block (param i32 i32) (result i64))
)
(global $ret_hi (mut i32) (i32.const 0))
(global $ret_lo (mut i32) (i32.const 0))
(func (export "returnHi") (result i32) (get_global $ret_hi))
(func (export "returnLo") (result i32) (get_global $ret_lo))
(module (func (export "test") (result i32)
(block (result i32)
i32.const 0
i32.const 0
br_if 0
i32.const 0
)
)
)
(module (func (export "test") (result i32)
(block (result i32)
(unreachable) (br_if 0 (i32.const 0) (i32.const 0)) (i32.const 0)
)
)
)