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

Enable ops outside guard. #110

Merged
merged 9 commits into from
Jul 23, 2024
74 changes: 36 additions & 38 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ do-notation = "0.1.3"
serde_json = "1.0"
sha2 = "0.9.5"
tempfile = "3.3.0"
clvmr = { version = "0.3.2", features = ["pre-eval"] }
clvmr = { version = "=0.3.3", features = ["pre-eval"] }
binascii = "0.1.4"
yaml-rust = "0.4"
linked-hash-map = "0.5.6"
Expand Down
1 change: 1 addition & 0 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,7 @@ pub fn launch_tool(stdout: &mut Stream, args: &[String], tool_name: &str, defaul
Some(max_cost as u64)
},
pre_eval_f,
new_operators: false,
strict: parsed_args
.get("strict")
.map(|_| true)
Expand Down
9 changes: 7 additions & 2 deletions src/classic/clvm_tools/stages/stage_0.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use clvm_rs::allocator::{Allocator, NodePtr};
use clvm_rs::chia_dialect::{ChiaDialect, NO_UNKNOWN_OPS};
use clvm_rs::chia_dialect::{ChiaDialect, ENABLE_BLS_OPS_OUTSIDE_GUARD, NO_UNKNOWN_OPS};
use clvm_rs::cost::Cost;
use clvm_rs::reduction::Response;

use clvm_rs::run_program::{run_program_with_pre_eval, PreEval};

#[derive(Default)]
pub struct RunProgramOption {
pub max_cost: Option<Cost>,
pub pre_eval_f: Option<PreEval>,
pub strict: bool,
pub new_operators: bool,
}

pub trait TRunProgram {
Expand Down Expand Up @@ -44,10 +46,13 @@ impl TRunProgram for DefaultProgramRunner {
option: Option<RunProgramOption>,
) -> Response {
let max_cost = option.as_ref().and_then(|o| o.max_cost).unwrap_or(0);
let new_operators = option.as_ref().map(|o| o.new_operators).unwrap_or_default();

run_program_with_pre_eval(
allocator,
&ChiaDialect::new(NO_UNKNOWN_OPS),
&ChiaDialect::new(
NO_UNKNOWN_OPS | ((new_operators as u32) * ENABLE_BLS_OPS_OUTSIDE_GUARD),
),
program,
args,
max_cost,
Expand Down
12 changes: 10 additions & 2 deletions src/compiler/clvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sha2::Digest;
use sha2::Sha256;

use crate::classic::clvm::__type_compatibility__::{bi_one, bi_zero};
use crate::classic::clvm_tools::stages::stage_0::TRunProgram;
use crate::classic::clvm_tools::stages::stage_0::{RunProgramOption, TRunProgram};

use crate::compiler::prims;
use crate::compiler::runtypes::RunFailure;
Expand Down Expand Up @@ -396,7 +396,15 @@ fn apply_op(
let converted_args = convert_to_clvm_rs(allocator, wrapped_args.clone())?;

runner
.run_program(allocator, converted_app, converted_args, None)
.run_program(
allocator,
converted_app,
converted_args,
Some(RunProgramOption {
new_operators: true,
..RunProgramOption::default()
}),
)
.map_err(|e| {
RunFailure::RunErr(
head.loc(),
Expand Down
48 changes: 48 additions & 0 deletions src/tests/compiler/cldb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,3 +454,51 @@ fn test_cldb_hierarchy_before_hex() {

compare_run_output(result, run_entries);
}

#[test]
fn test_cldb_operators_outside_guard() {
let filename = "coinid.clvm";
let loc = Srcloc::start(filename);
let inputs_outputs = [
(
"(coinid (sha256 (q . 3)) (sha256 (q . 3)) (q . 4))",
"()",
"0x9f7f12b86a583805a4442879b7b5b531469e45c7e753e5fd431058e90bf3fbec"
),
(
"(modpow (q . 2) (q . 8) (q . 10))",
"()",
"6"
),
(
"(% (q . 13) (q . 5))",
"()",
"3"
),
(
// resources/tests/bls/modern-bls-verify-signature.clsp
"(2 (1 59 (1 . 0xb00ab9a8af54804b43067531d96c176710c05980fccf8eee1ae12a4fd543df929cce860273af931fe4fdbc407d495f73114ab7d17ef08922e56625daada0497582340ecde841a9e997f2f557653c21c070119662dd2efa47e2d6c5e2de00eefa) (1 . 0x86243290bbcbfd9ae75bdece7981965350208eb5e99b04d5cd24e955ada961f8c0a162dee740be7bdc6c3c0613ba2eb1) 5) (4 (1) 1))",
"(0x0102030405)",
"()"
)
];

for (program, arg_str, expected) in inputs_outputs {
let parsed = parse_sexp(loc.clone(), program.bytes()).expect("should parse");
let args_parsed = parse_sexp(loc.clone(), arg_str.bytes()).expect("should parse");
let program_lines = Rc::new(vec![program.to_string()]);

assert_eq!(
run_clvm_in_cldb(
filename,
program_lines,
parsed[0].clone(),
HashMap::new(),
args_parsed[0].clone(),
&mut DoesntWatchCldb {},
FAVOR_HEX,
),
Some(expected.to_string())
);
}
}
3 changes: 1 addition & 2 deletions src/tests/compiler/optimizer/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ fn run_with_cost(
as_classic_env,
Some(RunProgramOption {
max_cost: Some(MAX_RUN_COST),
pre_eval_f: None,
strict: false,
..RunProgramOption::default()
}),
)
.map_err(|e| RunFailure::RunErr(sexp.loc(), format!("{} in {} {}", e.1, sexp, env)))
Expand Down
Loading