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
| let p = 7; | |
| for (let a = 0; a < p; a++) { | |
| for (let b = 0; b < p; b++) { | |
| let arr = []; | |
| for (let q = 0; q < p; q++) { | |
| for (let r = 0; r < p; r++) { | |
| //if (a == (b * q + r) && r < b) arr.push([a, b, q, r]); | |
| if (a == (b * q + r) % p && r < b) arr.push([a, b, q, r]); | |
| } | |
| } |
| template instances: 88 | |
| non-linear constraints: 5128 | |
| linear constraints: 0 | |
| public inputs: 65 | |
| public outputs: 1 | |
| private inputs: 81 | |
| private outputs: 0 | |
| wires: 5238 | |
| labels: 20290 |
| 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.