Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHIA-255: implement CHIP-34 #403

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ chia-bls = "0.4.0"
sha2 = "0.10.8"
openssl = { version = "=0.10.55", features = ["vendored"], optional = true }
hex-literal = "=0.4.1"
base64ct = "1.6.0"
# for secp sigs
k256 = { version = "0.13.1", features = ["ecdsa"] }
p256 = { version = "0.13.2", features = ["ecdsa"] }
# for keccak256
sha3 = "0.10.8"

[dev-dependencies]
rstest = "0.17.0"
Expand Down
9 changes: 7 additions & 2 deletions docs/new-operator-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@ Follow this checklist when adding operators:
Make sure to run this and fuzz for some time before landing the PR.
* extend the benchmark-clvm-cost.rs to include benchmarks for the new operator,
to establish its cost.
* The opcode decoding and dispatching happens in `src/ChiaDialect.rs`
* The opcode decoding and dispatching happens in `src/chia_dialect.rs`
* Add support for the new operators in `src/test_ops.rs` `parse_atom()`, to
compile the name of the operator to its corresponding opcode.
* if the operator(s) are part of an extension to `softfork`, add another value
to the `OperatorSet` enum.
* Add a new flag (in `src/chia_dialect.rs`) that controls whether the
operators are activated or not. This is required in order for the chain to exist
in a state *before* your soft-fork has activated, and behave consistently with
versions of the node that doesn't know about your new operators.
Make sure the value of the flag does not collide with any of the flags in
[chia_rs](https://github.com/Chia-Network/chia_rs/blob/main/src/gen/flags.rs).
[chia_rs](https://github.com/Chia-Network/chia_rs/blob/main/crates/chia-consensus/src/gen/flags.rs).
This is a quirk where both of these repos share the same flags space.
* expose the new flag(s) to python in chia_rs
* Once a soft-fork has activated, if everything on chain before the softfork is
compatible with the new rules (which is likely and ought to be the ambition
with all soft-forks), all logic surrounding activating or deactivating the
Expand Down
12 changes: 12 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ name = "allocator"
path = "fuzz_targets/allocator.rs"
test = false
doc = false

[[bin]]
name = "base64"
path = "fuzz_targets/base64.rs"
test = false
doc = false

[[bin]]
name = "keccak"
path = "fuzz_targets/keccak.rs"
test = false
doc = false
23 changes: 23 additions & 0 deletions fuzz/fuzz_targets/base64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_main]
use clvmr::base64_ops::{op_base64url_decode, op_base64url_encode};
use clvmr::{reduction::Reduction, Allocator, NodePtr};
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut a = Allocator::new();
let blob = a.new_atom(data).expect("failed to create atom");
let args = a
.new_pair(blob, NodePtr::NIL)
.expect("failed to create pair");
let Reduction(cost, node) =
op_base64url_encode(&mut a, args, 11000000000).expect("base64url_encode failed");
assert!(cost >= 170);

let args = a
.new_pair(node, NodePtr::NIL)
.expect("failed to create pair");
let Reduction(cost, node) =
op_base64url_decode(&mut a, args, 11000000000).expect("base64url_decode failed");
assert!(cost >= 400);
assert!(a.atom_eq(node, blob));
});
16 changes: 16 additions & 0 deletions fuzz/fuzz_targets/keccak.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![no_main]
use clvmr::keccak256_ops::op_keccak256;
use clvmr::{reduction::Reduction, Allocator, NodePtr};
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut a = Allocator::new();
let blob = a.new_atom(data).expect("failed to create atom");
let args = a
.new_pair(blob, NodePtr::NIL)
.expect("failed to create pair");
let Reduction(cost, node) = op_keccak256(&mut a, args, 11000000000).expect("keccak256 failed");
assert!(cost >= 210);
assert!(node.is_atom());
assert_eq!(a.atom_len(node), 32);
});
8 changes: 7 additions & 1 deletion fuzz/fuzz_targets/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
use libfuzzer_sys::fuzz_target;

use clvmr::allocator::{Allocator, NodePtr};
use clvmr::base64_ops::{op_base64url_decode, op_base64url_encode};
use clvmr::bls_ops::{
op_bls_g1_multiply, op_bls_g1_negate, op_bls_g1_subtract, op_bls_g2_add, op_bls_g2_multiply,
op_bls_g2_negate, op_bls_g2_subtract, op_bls_map_to_g1, op_bls_map_to_g2,
op_bls_pairing_identity, op_bls_verify,
};
use clvmr::core_ops::{op_cons, op_eq, op_first, op_if, op_listp, op_raise, op_rest};
use clvmr::cost::Cost;
use clvmr::keccak256_ops::op_keccak256;
use clvmr::more_ops::{
op_add, op_all, op_any, op_ash, op_coinid, op_concat, op_div, op_divmod, op_gr, op_gr_bytes,
op_logand, op_logior, op_lognot, op_logxor, op_lsh, op_mod, op_modpow, op_multiply, op_not,
Expand All @@ -20,7 +22,7 @@ use clvmr::serde::node_from_bytes;

type Opf = fn(&mut Allocator, NodePtr, Cost) -> Response;

const FUNS: [Opf; 45] = [
const FUNS: [Opf; 48] = [
op_if as Opf,
op_cons as Opf,
op_first as Opf,
Expand Down Expand Up @@ -68,6 +70,10 @@ const FUNS: [Opf; 45] = [
// Secp operators
op_secp256k1_verify as Opf,
op_secp256r1_verify as Opf,
// base64 operators
op_base64url_encode as Opf,
op_base64url_decode as Opf,
op_keccak256 as Opf,
Rigidity marked this conversation as resolved.
Show resolved Hide resolved
];

fuzz_target!(|data: &[u8]| {
Expand Down
Loading
Loading