Skip to content

Commit

Permalink
Fix builtin gas charging for repl builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Nov 4, 2024
1 parent 419b807 commit adccfca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pact-repl/Pact/Core/IR/Eval/Direct/Evaluator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pact/Pact/Core/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ coreBuiltinToUserText = \case

instance IsBuiltin CoreBuiltin where
builtinName = NativeName . coreBuiltinToText
builtinChargesGas _ = True
builtinArity = \case
CoreAdd -> 2
-- Num ->
Expand Down Expand Up @@ -783,6 +784,7 @@ data ReplOnlyBuiltin

instance IsBuiltin ReplOnlyBuiltin where
builtinName = NativeName . replBuiltinsToText
builtinChargesGas _ = False
builtinArity = \case
RExpect -> 3
RExpectFailure -> 2
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -961,6 +966,7 @@ replCoreBuiltinOnlyMap =
class Show b => IsBuiltin b where
builtinArity :: b -> Int
builtinName :: b -> NativeName
builtinChargesGas :: b -> Bool


instance Pretty CoreBuiltin where
Expand Down

0 comments on commit adccfca

Please sign in to comment.