Skip to content

Commit

Permalink
Better: classic already handled this differently
Browse files Browse the repository at this point in the history
  • Loading branch information
prozacchiwawa committed Jul 20, 2024
1 parent 860bbeb commit cb44f52
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/classic/clvm_tools/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,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
5 changes: 4 additions & 1 deletion src/classic/clvm_tools/stages/stage_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ 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,11 @@ 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 | ENABLE_BLS_OPS_OUTSIDE_GUARD),
&ChiaDialect::new(NO_UNKNOWN_OPS | ((new_operators as u32) * ENABLE_BLS_OPS_OUTSIDE_GUARD)),
program,
args,
max_cost,
Expand Down
7 changes: 5 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::{TRunProgram, RunProgramOption};

use crate::compiler::prims;
use crate::compiler::runtypes::RunFailure;
Expand Down Expand Up @@ -396,7 +396,10 @@ 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
12 changes: 0 additions & 12 deletions src/tests/classic/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2543,15 +2543,3 @@ fn test_include_bin_should_not_be_parsed() {
let result = do_basic_brun(&vec!["brun".to_string(), program]);
assert_eq!(result.trim(), "\"'test\"");
}

#[test]
fn test_coinid_outside_guard() {
let result = do_basic_run(&vec![
"run".to_string(),
"(coinid (sha256 3) (sha256 3) 4)".to_string(),
]);
assert_eq!(
result.trim(),
"0x9f7f12b86a583805a4442879b7b5b531469e45c7e753e5fd431058e90bf3fbec"
);
}
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

0 comments on commit cb44f52

Please sign in to comment.