Skip to content

Instantly share code, notes, and snippets.

@LCamel
LCamel / div.mjs
Created March 14, 2023 02:25
integer division
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]);
}
}
@LCamel
LCamel / circom.txt
Last active February 10, 2023 14:30
HashTower: 1M items, W=4 H=16
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
@LCamel
LCamel / PickOne.circom
Created February 9, 2023 14:23
PickOne
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);
@LCamel
LCamel / PickOneFromEachRow.circom
Created February 9, 2023 14:15
PickOneFromEachRow
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];
@LCamel
LCamel / Mux2D.circom
Last active February 9, 2023 13:48
Mux2D
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;
@LCamel
LCamel / A.sol
Created February 8, 2023 09:57
Poseidon library / contract hack
// 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);
@LCamel
LCamel / 10M_items.txt
Created January 20, 2023 15:41
HashTower Simulation
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 _ _ _ _
@LCamel
LCamel / HashTower.mjs
Last active January 18, 2023 13:31
HashTower (WIP)
"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;
@LCamel
LCamel / __CREATE2__CREATE__.md
Last active August 20, 2022 14:14
CREATE2 and CREATE
@LCamel
LCamel / __CREATE2__.md
Last active August 10, 2022 23:02
CREATE2 demo