Skip to content

Instantly share code, notes, and snippets.

View flyq's full-sized avatar
⚙️
Make Etherem Great Again

liquan.eth flyq

⚙️
Make Etherem Great Again
View GitHub Profile
init risc0 install env:
sudo apt install ca-certificates curl build-essential cmake ninja-build libssl-dev pkg-config

Need to be tested:

  • How to deal with cross terms generated by folding Gate/Wiring instances? We need to figure out a new folded instance same as relaxed R1CS, or any other tricks
  • Can we utilize the circuit(front-end) part of halo2, and proving system(back-end) part of halo2 directly?
@flyq
flyq / miniecdsa.py
Last active October 22, 2024 18:49
a broken deterministic ecdsa
#!/usr/bin/python3
from sympy.core.numbers import igcdex
def safe_div(x: int, y: int):
"""
Computes x / y and fails if x is not divisible by y.
"""
assert isinstance(x, int) and isinstance(y, int)
assert y != 0

Example Oracle on ICP

The importance of Oracle to a blockchain system is self-evident, and it is the only way for the blockchain to obtain off-chain information, including real-world asserts/businesses.

how chainlink works

Chainlink Data Feeds provide data that is aggregated from many data sources by a decentralized set of independent node operators. The Decentralized Data Model describes this in detail. However, there are some exceptions where data for a feed can come only from a single data source or where data values are calculated.

how oracle works

The solution provided by chainlink has been criticized by centralization, and users need to trust that the nodes of chainlink will not do evil. Because chainlink nodes do not run a consensus algorithm, they do not form an effective blockchain network.

import Debug "mo:base/Debug";
import Nat "mo:base/Nat";
import Array "mo:base/Array";
actor {
func swap(arr: [var Int], low: Nat, high: Nat) : [var Int] {
var tmp = arr[low];
arr[low] := arr[high];
arr[high] := tmp;
return arr;
@flyq
flyq / get cycles.md
Last active November 27, 2021 10:05

Q: 假如你不需要一个 Canister 了,可以卸载它。但怎么回收剩余的 cycles?请写明详细操作步骤。 A:

  1. 准备一个能接受 cycles 的 canister, 比如 cycles_wallet,或者新建一个 canister,里面新建一个 public update function,比如
import Nat "mo:base/Nat";
import Nat64 "mo:base/Nat64";
import Cycles "mo:base/ExperimentalCycles";

public func wallet_receive() : async { accepted: Nat64 } {
 let available = Cycles.available();

NNS subnet state export: Attempt to read the state of Ledger canister, but failed:

dfx canister --no-wallet --network ic call read_rs block '(306944)'
The Replica returned an error: code 5, message: "IC0503: Canister ywrdt-7aaaa-aaaah-qaaaa-cai trapped explicitly: Panicked at 'called `Result::unwrap()` on an `Err` value: (Some(3), "Canister ryjl3-tyaaa-aaaaa-aaaba-cai not found")', src/main.rs:112:21"

dfx canister --no-wallet --network ic call read_rs balance "(record { account=\"d3e13d4777e22367532053190b6c6ccf57444a61337e996242b1abfb52cf92c8\" })"
The Replica returned an error: code 5, message: "IC0503: Canister ywrdt-7aaaa-aaaah-qaaaa-cai trapped explicitly: Panicked at 'called `Result::unwrap()` on an `Err` value: (Some(3), "Canister ryjl3-tyaaa-aaaaa-aaaba-cai not found")', src/main.rs:92:12"

here is the source

import List "mo:base/List";
actor Example {
var sum = 0;
private var test = List.fromArray<Nat>([5,4,3,2,1,0]);
private var test1 = List.nil<Nat>();
let f2 = func self(x: Nat) {
sum := sum + x;
};
Hxw4UqXzNRNY6k3pLi6WRjNT32qYnYfdX8P97Ex9hKb5VPT
Proof of Work: https://github.com/flyq/kusama.network/commits/master
Compiling cita-network v20.2.0 (/home/flyq/workspaces/cita/cita/cita-network)
Compiling cita-bft v20.2.0 (/home/flyq/workspaces/cita/cita/cita-bft)
Compiling cita-auth v20.2.0 (/home/flyq/workspaces/cita/cita/cita-auth)
Compiling cita-chain v20.2.0 (/home/flyq/workspaces/cita/cita/cita-chain)
Compiling jsonrpc-proto v0.1.0 (https://github.com/citahub/cita-common.git?branch=develop#7a23d751)
Compiling chain-executor-mock v0.1.0 (/home/flyq/workspaces/cita/cita/tests/chain-executor-mock)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/flyq/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/flyq/workspaces/cita/cita/target/release/deps/chain_executor_mock-0ea0a0338851fc6a.chain_executor_mock.81ltuxb8-cgu.0.rcgu.o" "/home/flyq/workspaces/cita/cita/target/release/deps/chain_executor_mock-0ea0a0338851fc6a.chain_executor_mock.81ltuxb8-cgu.1.rcgu.o" "/home/flyq/workspaces/cita/