Skip to content

Instantly share code, notes, and snippets.

View hrmk1o3's full-sized avatar

Kc hrmk1o3

View GitHub Profile
@hrmk1o3
hrmk1o3 / indexed_merkle_tree.rs
Created August 1, 2023 13:16
This is an implementation of indexed Merkle tree described in https://eprint.iacr.org/2021/1263 .
use num::BigUint;
use plonky2::{
hash::{
hash_types::{HashOut, RichField},
merkle_proofs::MerkleProof,
},
plonk::config::Hasher,
};
use super::{hash::Leafable, merkle_tree::MerkleTree};
@hrmk1o3
hrmk1o3 / conditionally_verify_proof.rs
Created June 22, 2023 19:03
Improve the implementation of `conditionally_verify_proof` in plonky2
use std::time::Instant;
// plonky2 = "0.1.3"
use plonky2::{
field::{extension::Extendable, types::Field},
gates::noop::NoopGate,
hash::hash_types::{HashOutTarget, MerkleCapTarget, RichField},
iop::{
target::BoolTarget,
witness::{PartialWitness, WitnessWrite},
//! https://github.com/mir-protocol/plonky2
//! The following code can be used to display the witness of `x`.
//! `builder.add_simple_generator(DisplayGenerator { target: x });`
#[derive(Clone, Debug)]
struct DisplayGenerator {
target: Target,
}
impl<F: Field> SimpleGenerator<F> for DisplayGenerator {
use std::time::Instant;
use plonky2::{
field::types::Field,
hash::{hash_types::HashOut, poseidon::PoseidonHash},
iop::witness::{PartialWitness, Witness},
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::CircuitConfig,
config::{GenericConfig, PoseidonGoldilocksConfig},
@hrmk1o3
hrmk1o3 / simple_recursion.rs
Last active September 20, 2022 11:50
recursive ZK circuit in Plonky2
use std::time::Instant;
use plonky2::{
field::goldilocks_field::GoldilocksField,
iop::{
target::Target,
witness::{PartialWitness, Witness},
},
plonk::{
circuit_builder::CircuitBuilder,
@hrmk1o3
hrmk1o3 / error.rs
Created February 6, 2022 07:07
Error Handling for Rust
use std::fs::File;
use anyhow::Context;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum MyError {
#[error("HogeError: {0}")]
HogeError(u8),
#[error("FooError: {0}")]
const Eos = require("eosjs");
const eos = Eos({
keyProvider: [], // append private key
httpEndpoint: "https://api-kylin.eosasia.one:443",
chainId: "5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191",
});
const myContractName = "mokemokecore";
@hrmk1o3
hrmk1o3 / sample.sol
Created November 17, 2018 07:43
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity ^0.4.21;
contract SpecialVariables {
function exec() public payable returns (
address block_coinbase,
uint256 block_difficulty,
uint256 block_gaslimit,
uint256 block_number,
uint256 block_timestamp,
uint256 gas_left,
@hrmk1o3
hrmk1o3 / CommunityToken.sol
Last active November 16, 2018 13:18
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity ^0.4.21;
import "./PCS.sol";
import "./SafeMath.sol";
contract CommunityToken is PCS {
using SafeMath for uint256;
uint256 internal tokenPrice;
address[] internal serviceProviderList;
@hrmk1o3
hrmk1o3 / getCode.sol
Created November 15, 2018 05:33
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity ^0.4.0;
library GetCode {
function at(address _addr) public view returns (bytes o_code) {
assembly {
// retrieve the size of the code, this needs assembly
let size := extcodesize(_addr)
// allocate output byte array - this could also be done without assembly
// by using o_code = new bytes(size)
o_code := mload(0x40)