Skip to content

Instantly share code, notes, and snippets.

@LCamel
LCamel / false_positive.js
Last active May 29, 2023 14:12
False positives for the LessThan circuit (caused by overflow)
// https://github.com/iden3/circomlib/blob/master/circuits/comparators.circom
const p = 23;
const N = 2;
var fp = []; // false positive
for (var x = 0; x < p; x++) {
fp[x] = [];
for (var y = 0; y < p; y++) {
fp[x][y] = ' ';
@LCamel
LCamel / PickOne.circom
Last active May 27, 2023 12:33
PickOne experiments
pragma circom 2.1.4;
include "circomlib/multiplexer.circom";
include "circomlib/comparators.circom";
// Pick in[sel]
template PickOne(N) {
signal input in[N];
signal input sel;
signal output out;
@LCamel
LCamel / a.txt
Created May 24, 2023 13:23
upgrade poseidon-solidity from 0.0.4 to 0.0.5 will solve this problem
% yarn workspace hashtower.sol test
Warning: Contract code size exceeds 24576 bytes (a limit introduced in Spurious Dragon). This contract may not be deployable on mainnet. Consider enabling the optimizer (with a low "runs" value!), turning off revert strings, or using libraries.
--> poseidon-solidity/PoseidonT3.sol:4:1:
|
4 | library PoseidonT3 {
| ^ (Relevant source part starts here and spans across multiple lines).
Compiled 3 Solidity files successfully
@LCamel
LCamel / a.txt
Created May 24, 2023 10:04
hashtower.sol
% yarn workspace hashtower.sol test:coverage
Version
=======
> solidity-coverage: v0.8.2
Instrumenting for coverage...
=============================
> HashTowerHashChain.sol
import { poseidon } from "circomlibjs"; // 0.0.8
import { poseidon2 } from "poseidon-lite"; // 0.2.0
for (let j = 0; j < 5; j++) {
console.time("circomlibjs")
for (let i = 0n; i < 10000; i++) { poseidon([i, i + 1n]) }
console.timeEnd("circomlibjs")
console.time("poseidon-lite")
for (let i = 0n; i < 10000; i++) { poseidon2([i, i + 1n]) }
@LCamel
LCamel / gas.txt
Created March 25, 2023 05:41
HashTowerWithHashList
lcamel@lcameldeMacBook-Pro POC % time npx mocha test/ContractTest.mjs
The Contract
add
=== i: 0
add: gasUsed: 50266
0n
=== i: 1
add: gasUsed: 105620
@LCamel
LCamel / collision_cost.mjs
Created March 23, 2023 16:32
collision cost
// https://discord.com/channels/943612659163602974/1065263015622090802/1088499598579990589
let f = (x) => 4 * 2**x * 2**(129/4 - x/8) + 2**(129 - x/2);
for (let x = 0; x <= 256; x++) {
console.log(x, Math.log2(f(x)));
}
@LCamel
LCamel / a.txt
Created March 15, 2023 02:24
Poseidon hash with 7 inputs ?
% node
Welcome to Node.js v16.15.1.
Type ".help" for more information.
> var a = require("circomlibjs")
undefined
> a.poseidon_gencontract.createCode(1).length / 2
6858
> a.poseidon_gencontract.createCode(2).length / 2
9756
> a.poseidon_gencontract.createCode(6).length / 2
@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