Skip to content

Instantly share code, notes, and snippets.

View dangerousfood's full-sized avatar

Joseph Delong dangerousfood

View GitHub Profile
@dangerousfood
dangerousfood / privacy-pools-ceremony_attestation.log
Created February 26, 2025 17:37
Attestation for Privacy Pools Ceremony MPC Phase 2 Trusted Setup ceremony
Hey, I'm dangerousfood-4099038 and I have contributed to the Privacy Pools Ceremony.
The following are my contribution signatures:
Circuit # 1 (withdraw)
Contributor # 382
Contribution Hash:
afcc0420 400ac5f9 2b8ed8db 0c7312b9
77e7752f 32121933 efbe5c67 7b079ec6
1c1ffcfc 13ce0abf 26f97f72 29c92f31
a32cc8b7 cb4953b9 f0fc9132 f42e5fcc
@dangerousfood
dangerousfood / sushi_xsushi_exchange_rate.js
Created January 18, 2021 17:52
A method to get the SUSHI to xSushi exchange rate from the contracts
let sushi = new ethers.Contract('0x6b3595068778dd592e39a122f4f5a5cf09c90fe2', abi, provider)
let totalSushiStakedinXSushi = await sushi.methods.balanceOf('0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272').call()
let xSushi = new ethers.Contract('0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272', abi, provider)
let totalXSushiSupply = await xSushi.methods.totalSupply().call()
let exchangeRate = totalSushiStakedinBar.div(totalXSushiSupply)
@public
@constant
def get_deposit_root() -> bytes32:
root: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
size: uint256 = self.deposit_count
for h in range(DEPOSIT_CONTRACT_TREE_DEPTH):
if bitwise_and(size, 1) == 1:
root = sha3(concat(self.branch[h], root))
else:
root = sha3(concat(root, self.zerohashes[h]))
public List<Bytes32> getProofTreeByIndex(int index) {
if (dirty) calcBranches();
List<Bytes32> proof = new ArrayList<Bytes32>();
for (int i = 0; i < height; i++) {
index = index % 2 == 1 ? index - 1 : index + 1;
if (index < tree.get(i).size()) proof.add(tree.get(i).get(index));
else proof.add(zeroHashes.get(i));
index /= 2;
}
return proof;
private void calcBranches() {
for (int i = 0; i < height; i++) {
List<Bytes32> parent = tree.get(i + 1);
List<Bytes32> child = tree.get(i);
for (int j = 0; j < child.size(); j += 2) {
Bytes32 leftNode = child.get(j);
Bytes32 rightNode = (j + 1 < child.size()) ? child.get(j + 1) : zeroHashes.get(i);
parent.add(j / 2, Hash.sha2_256(Bytes.concatenate(leftNode, rightNode)));
}
}
public void add(int index, Bytes32 leaf) {
dirty = true;
tree.get(0).add(index, leaf);
}
public static List<Bytes32> generateZeroHashes(int height) {
List<Bytes32> zeroHashes = new ArrayList<Bytes32>();
for (int i = 0; i < height; i++) zeroHashes.add(Bytes32.ZERO);
for (int i = 0; i < height - 1; i++)
zeroHashes.set(i + 1, Hash.sha2_256(Bytes.concatenate(zeroHashes.get(i), zeroHashes.get(i))));
return zeroHashes;
}
private final List<List<Bytes32>> tree;
private final List<Bytes32> zeroHashes;
private final int height;
private boolean dirty = true;
public MerkleTree(int height) {
assert (height > 1);
this.height = height;
tree = new ArrayList<List<Bytes32>>();
for (int i = 0; i <= height; i++) {
/*
* Copyright 2019 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
public static boolean verify_merkle_branch(
Bytes32 leaf, List<Bytes32> proof, int depth, int index, Bytes32 root) {
Bytes32 value = leaf;
for (int i = 0; i < depth; i++) {
if (Math.floor(index / Math.pow(2, i)) % 2 != 0) {
value = Hash.sha2_256(Bytes.concatenate(proof.get(i), value));
} else {
value = Hash.sha2_256(Bytes.concatenate(value, proof.get(i)));
}
}