From adccfcaaa9bb8f30144850a802795790a9f82ec4 Mon Sep 17 00:00:00 2001 From: jmcardon Date: Mon, 4 Nov 2024 15:15:52 -0500 Subject: [PATCH] Fix builtin gas charging for repl builtins --- pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs | 2 +- pact/Pact/Core/Builtin.hs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs b/pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs index ddc40f5f..c182e9a7 100644 --- a/pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs +++ b/pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs @@ -675,7 +675,7 @@ applyLam -> EvalM e b i (EvalValue e b i) applyLam nclo@(N (NativeFn b env fn arity i)) args | arity == argLen = do - chargeFlatNativeGas i b + when (builtinChargesGas b) $ chargeFlatNativeGas i b fn i b env args | argLen > arity = throwExecutionError i ClosureAppliedToTooManyArgs | null args = return (VClosure nclo) diff --git a/pact/Pact/Core/Builtin.hs b/pact/Pact/Core/Builtin.hs index cd0f0f2e..9e3440e0 100644 --- a/pact/Pact/Core/Builtin.hs +++ b/pact/Pact/Core/Builtin.hs @@ -566,6 +566,7 @@ coreBuiltinToUserText = \case instance IsBuiltin CoreBuiltin where builtinName = NativeName . coreBuiltinToText + builtinChargesGas _ = True builtinArity = \case CoreAdd -> 2 -- Num -> @@ -783,6 +784,7 @@ data ReplOnlyBuiltin instance IsBuiltin ReplOnlyBuiltin where builtinName = NativeName . replBuiltinsToText + builtinChargesGas _ = False builtinArity = \case RExpect -> 3 RExpectFailure -> 2 @@ -843,6 +845,9 @@ instance IsBuiltin b => IsBuiltin (ReplBuiltin b) where builtinArity = \case RBuiltinWrap b -> builtinArity b RBuiltinRepl b -> builtinArity b + builtinChargesGas = \case + RBuiltinWrap b -> builtinChargesGas b + RBuiltinRepl b -> builtinChargesGas b -- RLoad -> 1 @@ -961,6 +966,7 @@ replCoreBuiltinOnlyMap = class Show b => IsBuiltin b where builtinArity :: b -> Int builtinName :: b -> NativeName + builtinChargesGas :: b -> Bool instance Pretty CoreBuiltin where