Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
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
2 changes: 1 addition & 1 deletion docs/en/pact-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1928,7 +1928,7 @@ Retreive any accumulated events and optionally clear event state. Object returne
*→* `[string]`


Queries, or with arguments, sets execution config flags. Valid flags: ["AllowReadInLocal","DisableHistoryInTransactionalMode","DisableInlineMemCheck","DisableModuleInstall","DisableNewTrans","DisablePact40","DisablePact420","DisablePact43","DisablePact431","DisablePact44","DisablePact45","DisablePact46","DisablePact47","DisablePact48","DisablePact49","DisablePactEvents","DisableRuntimeReturnTypeChecking","EnforceKeyFormats","OldReadOnlyBehavior","PreserveModuleIfacesBug","PreserveModuleNameBug","PreserveNsModuleInstallBug","PreserveShowDefs"]
Queries, or with arguments, sets execution config flags. Valid flags: ["AllowReadInLocal","DisableHistoryInTransactionalMode","DisableInlineMemCheck","DisableModuleInstall","DisableNewTrans","DisablePact40","DisablePact410","DisablePact420","DisablePact43","DisablePact431","DisablePact44","DisablePact45","DisablePact46","DisablePact47","DisablePact48","DisablePact49","DisablePactEvents","DisableRuntimeReturnTypeChecking","EnforceKeyFormats","OldReadOnlyBehavior","PreserveModuleIfacesBug","PreserveModuleNameBug","PreserveNsModuleInstallBug","PreserveShowDefs"]
```lisp
pact> (env-exec-config ['DisableHistoryInTransactionalMode]) (env-exec-config)
["DisableHistoryInTransactionalMode"]
Expand Down
7 changes: 5 additions & 2 deletions src/Pact/Gas/Table.hs
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,17 @@ tableGasModel gasConfig =
gasToMilliGas $ fromIntegral n * _gasCostConfig_sortFactor gasConfig
GConcatenation i j -> gasToMilliGas $
fromIntegral (i + j) * _gasCostConfig_concatenationFactor gasConfig
GTextConcatenation nChars nStrings ->
GTextConcatenation nChars nStrings fixupDivByZero ->
let
MilliGas offsetCost = _gasCostConfig_textConcatenationFactorOffset gasConfig
MilliGas charCost = _gasCostConfig_textConcatenationFactorStringLen gasConfig
MilliGas stringCost = _gasCostConfig_textConcatenationFactorStrings gasConfig

avgDenom | fixupDivByZero = max (fromIntegral nStrings) 1
| otherwise = fromIntegral nStrings

costForAverageStringLength =
(fromIntegral nChars * charCost) `div` fromIntegral nStrings
(fromIntegral nChars * charCost) `div` avgDenom
costForNumberOfStrings =
fromIntegral nStrings * stringCost
in
Expand Down
3 changes: 2 additions & 1 deletion src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ concat' :: GasRNativeFun e
concat' i [TList ls _ _] = do

disablePact48 <- isExecutionFlagSet FlagDisablePact48
fixupDivByZero <- not <$> isExecutionFlagSet FlagDisablePact410
let concatGasCost =
if disablePact48
then
Expand All @@ -1301,7 +1302,7 @@ concat' i [TList ls _ _] = do
_ -> 0
nStrings = V.length ls
in
GTextConcatenation nChars nStrings
GTextConcatenation nChars nStrings fixupDivByZero
computeGas' i concatGasCost $
let
ls' = V.toList ls
Expand Down
10 changes: 6 additions & 4 deletions src/Pact/Types/Gas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ data GasArgs
-- ^ Cost of sorting by lookup fields
| GConcatenation !Int !Int
-- ^ Cost of concatenating two strings before pact 4.8, lists, and objects
| GTextConcatenation !Int !Int
-- ^ Cost of concatenating a list of strings with the given total character
-- count and list length after pact 4.8
| GTextConcatenation !Int !Int !Bool
-- ^ Cost of concatenating a list of strings in pact ≥4.8, given
-- 1. total character count,
-- 2. list length, and
-- 3. whether to fixup division by zero (pact ≥4.10).
| GUnreduced ![Term Ref]
-- ^ Cost of using a native function
| GPostRead !ReadValue
Expand Down Expand Up @@ -224,7 +226,7 @@ instance Pretty GasArgs where
GSelect {} -> "GSelect"
GSortFieldLookup i -> "GSortFieldLookup:" <> pretty i
GConcatenation i j -> "GConcatenation:" <> pretty i <> colon <> pretty j
GTextConcatenation nChars nStrings -> "GTextConcatenation:" <> pretty nChars <> colon <> pretty nStrings
GTextConcatenation nChars nStrings fixupDiv -> "GTextConcatenation:" <> pretty nChars <> colon <> pretty nStrings <> colon <> pretty fixupDiv
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes changing this Pretty instance doesn't participate in on-chain computations. I skimmed through the code and found no evidence it does, but worth double-checking.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, @jmcardon ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not. Gas logs are not part of txlog outputs that get hashed.

GUnreduced {} -> "GUnreduced"
GPostRead rv -> "GPostRead:" <> pretty rv
GPreWrite wv szVer -> "GWrite:" <> pretty wv <> colon <> pretty szVer
Expand Down
2 changes: 2 additions & 0 deletions src/Pact/Types/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ data ExecutionFlag
| FlagDisablePact48
-- | Disable Pact 4.9 Features
| FlagDisablePact49
-- | Disable Pact 4.10 Features
| FlagDisablePact410
deriving (Eq,Ord,Show,Enum,Bounded)

-- | Flag string representation
Expand Down
6 changes: 6 additions & 0 deletions tests/pact/gas.repl
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,12 @@ d.G3
(env-gas 0)
(concat strings_1000_2000)
(expect "calling (concat strings_1000_2000)" 151 (env-gas))

;; Test issue #1316
(expect "concat gassing works on empty list" "" (concat []))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


(env-exec-config ["DisablePact410"])
(expect-failure "concat gassing replicates 4.8 behaviour on empty list" "divide by zero" (concat []))
(commit-tx)

(begin-tx)
Expand Down