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-902 make Program.run() and Program.run_with_cost() default to enabling all the most recent features #18370

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
18 changes: 18 additions & 0 deletions chia/_tests/clvm/test_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,28 @@ def test_run() -> None:
ret = div.run([10, -5])
assert ret.atom == bytes([0xFE])

# run()
with pytest.raises(ValueError, match="div operator with negative operands is deprecated"):
cost, ret = div.run_with_cost(100000, [10, -5], 0)

cost, ret = div.run_with_cost(100000, [10, -5], ENABLE_FIXED_DIV)
assert cost == 1107
print(ret)
assert ret.atom == bytes([0xFE])

# run_with_flags()
with pytest.raises(ValueError, match="div operator with negative operands is deprecated"):
cost, ret = div.run_with_flags(100000, 0, [10, -5])

cost, ret = div.run_with_flags(100000, ENABLE_FIXED_DIV, [10, -5])
assert cost == 1107
print(ret)
assert ret.atom == bytes([0xFE])

# run_with_cost()
with pytest.raises(ValueError, match="div operator with negative operands is deprecated"):
ret = div.run([10, -5], 100000, 0)

ret = div.run([10, -5], 100000, ENABLE_FIXED_DIV)
print(ret)
assert ret.atom == bytes([0xFE])
26 changes: 13 additions & 13 deletions chia/types/blockchain_format/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@

INFINITE_COST = 11000000000

DEFAULT_FLAGS = (
ENABLE_SOFTFORK_CONDITION
| ENABLE_BLS_OPS_OUTSIDE_GUARD
| ENABLE_FIXED_DIV
| AGG_SIG_ARGS
| ENABLE_MESSAGE_CONDITIONS
| DISALLOW_INFINITY_G1
| MEMPOOL_MODE
)

T_CLVMStorage = TypeVar("T_CLVMStorage", bound=CLVMStorage)
T_Program = TypeVar("T_Program", bound="Program")
Expand Down Expand Up @@ -139,22 +148,13 @@ def _run(self, max_cost: int, flags: int, args: Any) -> Tuple[int, Program]:
cost, r = run_chia_program(self.as_bin(), prog_args.as_bin(), max_cost, flags)
return cost, Program.to(r)

def run_with_cost(self, max_cost: int, args: Any) -> Tuple[int, Program]:
def run_with_cost(self, max_cost: int, args: Any, flags=DEFAULT_FLAGS) -> Tuple[int, Program]:
# when running puzzles in the wallet, default to enabling all soft-forks
# as well as enabling mempool-mode (i.e. strict mode)
default_flags = (
ENABLE_SOFTFORK_CONDITION
| ENABLE_BLS_OPS_OUTSIDE_GUARD
| ENABLE_FIXED_DIV
| AGG_SIG_ARGS
| ENABLE_MESSAGE_CONDITIONS
| DISALLOW_INFINITY_G1
| MEMPOOL_MODE
)
return self._run(max_cost, default_flags, args)
return self._run(max_cost, flags, args)

def run(self, args: Any) -> Program:
cost, r = self.run_with_cost(INFINITE_COST, args)
def run(self, args: Any, max_cost=INFINITE_COST, flags=DEFAULT_FLAGS) -> Program:
cost, r = self._run(max_cost, flags, args)
return r

def run_with_flags(self, max_cost: int, flags: int, args: Any) -> Tuple[int, Program]:
Expand Down
Loading