Replacing code with CREATE2 and CREATE.
- Repo: https://github.com/LCamel/ethereum-snippets/tree/main/medium_init_create2
- Article: to be published
- Article gist: https://gist.github.com/LCamel/bf0f173f06c6651c192b01bd48c4de74
pragma circom 2.1.2; | |
include "circomlib/multiplexer.circom"; | |
template PickOne(N) { | |
signal input in[N]; | |
signal input sel; | |
signal output out; | |
component mux = Multiplexer(1, N); |
pragma circom 2.1.2; | |
include "circomlib/multiplexer.circom"; | |
template PickOneFromEachRow(ROWS, COLS) { | |
signal input in[ROWS][COLS]; | |
signal input whichCol[ROWS]; | |
signal output out[ROWS]; | |
component selCol[ROWS]; |
pragma circom 2.1.2; | |
include "circomlib/multiplexer.circom"; | |
// get in[row][column] | |
template Mux2D(ROWS, COLS) { | |
signal input in[ROWS][COLS]; | |
signal input row; | |
signal input column; | |
signal output out; |
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.18; | |
// HACK: PROTOTYPING ONLY: use "contract" with a fixed address to avoid compiler library settings | |
contract Poseidon4 { | |
function poseidon(uint256[4] memory) public pure returns (uint256) {} | |
} | |
// goerli: after block 8166444 | |
Poseidon4 constant P = Poseidon4(0x3b44AA63Ac599170357dC587880fC30E506612e7); |
Simulation of add() 10,000,000 items: | |
For each add() call: | |
average storage read = 2.33 slots | |
average storage write = 2.33 slots | |
average hash call = 0.33 times (PoseidonT5) | |
lv 19 _ _ _ _ | |
lv 18 _ _ _ _ | |
lv 17 _ _ _ _ |
"use strict"; | |
import { poseidon } from "circomlibjs"; // for off-line computing | |
//import { groth16 } from "snarkjs"; | |
//import { ethers } from "ethers"; | |
const MAX_LEVELS = 32; | |
class HashTower { | |
constructor(hashInputCount) { | |
this.hashInputCount = hashInputCount; |
Replacing code with CREATE2 and CREATE.
This script demostrates how to deploy different code at the same address.
This script contains a Javascript-embedable EVM assembler and a generic deployer written in assembly.
import java.util.Arrays; | |
import java.util.Random; | |
public class AAA { | |
public static void main(String[] args) { | |
boolean[] board = new boolean[25]; | |
int n = 0; | |
int N = 1000000; | |
for (int i = 0; i < N; i++) { | |
pick(board, 14); |