From a8801ebc77882c12e3c798bdd1666d1a1a184c79 Mon Sep 17 00:00:00 2001 From: jmcardon Date: Tue, 22 Oct 2024 14:03:07 -0400 Subject: [PATCH] Adjust gas costs down --- pact-tests/gas-goldens/builtinGas.golden | 194 +++++++++--------- .../legacy-serial-tests/coin-v5/coin-v5.repl | 12 +- pact-tests/pact-tests/coin-v1.repl | 16 +- pact-tests/pact-tests/coin-v5.repl | 18 +- pact-tests/pact-tests/side-effects.repl | 4 +- pact/Pact/Core/Gas/TableGasModel.hs | 17 +- 6 files changed, 134 insertions(+), 127 deletions(-) diff --git a/pact-tests/gas-goldens/builtinGas.golden b/pact-tests/gas-goldens/builtinGas.golden index 27eda504..a50b3494 100644 --- a/pact-tests/gas-goldens/builtinGas.golden +++ b/pact-tests/gas-goldens/builtinGas.golden @@ -1,124 +1,124 @@ -!=: 401 +!=: 201 &: 250 -*: 227 -+: 230 --: 230 -/: 227 -<: 464 -<=: 464 -=: 401 ->: 464 ->=: 464 -^: 968 -abs: 200 -acquire-module-admin: 297894 +*: 127 ++: 130 +-: 130 +/: 127 +<: 264 +<=: 264 +=: 201 +>: 264 +>=: 264 +^: 868 +abs: 100 +acquire-module-admin: 234194 add-time: 750 -and?: 1128 -at: 906 +and?: 628 +at: 706 base64-decode: 331 base64-encode: 311 -bind: 677 -ceiling: 400 +bind: 477 +ceiling: 200 chain-data: 500 -compose-capability: 514500 -compose: 4460 -concat: 920 -cond: 1202 -contains: 605 -continue: 441250 -create-capability-guard: 227850 -create-capability-pact-guard: 246800 -create-module-guard: 188300 -create-pact-guard: 210050 -create-principal: 2302 -create-table: 466600 +compose-capability: 390200 +compose: 2760 +concat: 820 +cond: 602 +contains: 405 +continue: 312950 +create-capability-guard: 173950 +create-capability-pact-guard: 184700 +create-module-guard: 142900 +create-pact-guard: 156050 +create-principal: 2002 +create-table: 423300 days: 278 -dec: 200 -define-keyset: 8404 -define-namespace: 44212 -describe-keyset: 108404 -describe-module: 262700 -describe-namespace: 150124 -describe-table: 566600 +dec: 100 +define-keyset: 6804 +define-namespace: 37212 +describe-keyset: 106804 +describe-module: 224100 +describe-namespace: 140174 +describe-table: 523300 diff-time: 1414 -distinct: 3176 -drop: 1400 -emit-event: 263650 -enforce-guard: 3566 -enforce-keyset: 3566 +distinct: 2176 +drop: 1000 +emit-event: 200350 +enforce-guard: 3166 +enforce-keyset: 3166 enforce-verifier: 10150 -enumerate: 824 +enumerate: 524 exp: 4534 -filter: 4460 -floor: 400 -fold-db: 40525850 -fold: 1490 +filter: 2760 +floor: 200 +fold-db: 40453150 +fold: 1090 format-time: 1041 -format: 2000 -hash: 500 +format: 1900 +hash: 300 hours: 277 hyperlane-decode-token-message: 2175 hyperlane-encode-token-message: 2475 hyperlane-message-id: 2743 -identity: 200 -insert: 525650 -install-capability: 670489 -int-to-str: 1000 +identity: 100 +insert: 452950 +install-capability: 505689 +int-to-str: 800 is-charset: 1788 -is-principal: 797 -keys: 40525650 -keyset-ref-guard: 10425 -length: 1101 +is-principal: 597 +keys: 40452950 +keyset-ref-guard: 8825 +length: 801 list-modules: 100000 ln: 2016 log: 2090 -make-list: 225 -map: 1715 +make-list: 125 +map: 1315 minutes: 276 -mod: 200 -namespace: 44224 -negate: 200 -not: 664 -not?: 664 -or?: 664 -pact-id: 225950 -pairing-check: 12009033 +mod: 100 +namespace: 37224 +negate: 100 +not: 364 +not?: 364 +or?: 364 +pact-id: 169750 +pairing-check: 11063933 parse-time: 602 -point-add: 5600 +point-add: 5500 poseidon-hash-hack-a-chain: 6393700 -read-decimal: 503 -read-integer: 503 -read-keyset: 8808 -read-msg: 503 -read-string: 503 -read: 534550 -remove: 460 -require-capability: 402750 -resume: 515531 -reverse: 800 -round: 400 -scalar-mult: 360400 -select: 40525800 -shift: 1286 -show: 1400 -sort: 1400 +read-decimal: 303 +read-integer: 303 +read-keyset: 7008 +read-msg: 303 +read-string: 303 +read: 457650 +remove: 360 +require-capability: 304750 +resume: 380331 +reverse: 700 +round: 200 +scalar-mult: 360300 +select: 40453100 +shift: 886 +show: 1300 +sort: 1200 sqrt: 2022 -static-redeploy: 298900 -str-to-int: 708 +static-redeploy: 199200 +str-to-int: 408 str-to-list: 751 -take: 2200 +take: 1800 time: 500 -tx-hash: 200 -typeof-principal: 997 -typeof: 200 -update: 584750 -validate-principal: 4540 -where: 2340 -with-default-read: 540016 -with-read: 534833 -write: 525650 +tx-hash: 100 +typeof-principal: 797 +typeof: 100 +update: 482650 +validate-principal: 3940 +where: 1640 +with-default-read: 460916 +with-read: 457833 +write: 452950 xor: 500 -yield: 328150 -zip: 4920 +yield: 247650 +zip: 4320 |: 500 ~: 250 \ No newline at end of file diff --git a/pact-tests/legacy-serial-tests/coin-v5/coin-v5.repl b/pact-tests/legacy-serial-tests/coin-v5/coin-v5.repl index a27e7fd8..f3de8fe8 100644 --- a/pact-tests/legacy-serial-tests/coin-v5/coin-v5.repl +++ b/pact-tests/legacy-serial-tests/coin-v5/coin-v5.repl @@ -51,7 +51,7 @@ (env-gaslog) (expect "Gas cost of coin contract account creation" - 69 (env-gas)) + 36 (env-gas)) (create-account 'doug (read-keyset 'doug)) @@ -91,7 +91,7 @@ (env-gaslog) (expect "Gas cost of querying an account's balance" - 12 (env-gas)) + 6 (env-gas)) ; account information checks out for new accounts (env-gas 0) (env-gaslog) @@ -102,7 +102,7 @@ (env-gaslog) (expect "Gas cost of querying the details of an account" - 13 (env-gas)) + 7 (env-gas)) (commit-tx) @@ -128,7 +128,7 @@ (env-gaslog) (expect "Gas cost of testing the DEBIT capability" - 14 (env-gas)) + 8 (env-gas)) ; debit tests (expect-failure @@ -396,7 +396,7 @@ (env-gaslog) (expect "Gas cost of transfer" - 185 (env-gas)) + 99 (env-gas)) (expect-failure "emily->doug capability used up" "TRANSFER exceeded" @@ -433,7 +433,7 @@ (transfer-create 'doug 'will (read-keyset 'will) 1.0)) (env-gaslog) (expect - "Gas cost of transfer-create" 171 (env-gas)) + "Gas cost of transfer-create" 93 (env-gas)) (expect "doug now has 0.4 coins" diff --git a/pact-tests/pact-tests/coin-v1.repl b/pact-tests/pact-tests/coin-v1.repl index d9184cef..8d1e7802 100644 --- a/pact-tests/pact-tests/coin-v1.repl +++ b/pact-tests/pact-tests/coin-v1.repl @@ -9,14 +9,14 @@ (env-gaslog) (expect "Gas cost of loading fungible contract" - 844 (env-gas)) + 657 (env-gas)) (env-gas 0) (env-gaslog) (load "coin-v1/coin.pact") (env-gaslog) (expect "Gas cost of loading coin contract" - 16389 (env-gas)) + 12562 (env-gas)) (env-gas 0) (commit-tx) @@ -50,7 +50,7 @@ (env-gaslog) (expect "Gas cost of coin contract account creation" - 65 (env-gas)) + 33 (env-gas)) (create-account 'doug (read-keyset 'doug)) @@ -90,7 +90,7 @@ (env-gaslog) (expect "Gas cost of querying an account's balance" - 12 (env-gas)) + 6 (env-gas)) ; account information checks out for new accounts (env-gas 0) (env-gaslog) @@ -101,7 +101,7 @@ (env-gaslog) (expect "Gas cost of querying the details of an account" - 13 (env-gas)) + 7 (env-gas)) (commit-tx) @@ -127,7 +127,7 @@ (env-gaslog) (expect "Gas cost of testing the DEBIT capability" - 14 (env-gas)) + 8 (env-gas)) ; debit tests (expect-failure @@ -395,7 +395,7 @@ (env-gaslog) (expect "Gas cost of transfer" - 185 (env-gas)) + 99 (env-gas)) (expect-failure "emily->doug capability used up" "TRANSFER exceeded" @@ -432,7 +432,7 @@ (transfer-create 'doug 'will (read-keyset 'will) 1.0)) (env-gaslog) (expect - "Gas cost of transfer-create" 168 (env-gas)) + "Gas cost of transfer-create" 90 (env-gas)) (expect "doug now has 0.4 coins" diff --git a/pact-tests/pact-tests/coin-v5.repl b/pact-tests/pact-tests/coin-v5.repl index b2d20cfe..1f14db5e 100644 --- a/pact-tests/pact-tests/coin-v5.repl +++ b/pact-tests/pact-tests/coin-v5.repl @@ -8,7 +8,7 @@ (env-gaslog) (expect "Gas cost of loading fungible contract" - 918 (env-gas)) + 713 (env-gas)) (commit-tx) (env-gasmodel "table") @@ -18,7 +18,7 @@ (env-gaslog) (expect "Gas cost of loading fungible-xchain contract" - 371 (env-gas)) + 291 (env-gas)) (commit-tx) (begin-tx) (env-gas 0) @@ -26,7 +26,7 @@ (env-gaslog) (expect "Gas cost of loading coin contract" - 20539 + 15588 (env-gas)) (create-table coin.coin-table) @@ -63,7 +63,7 @@ (env-gaslog) (expect "Gas cost of coin contract account creation" - 69 (env-gas)) + 36 (env-gas)) (create-account 'doug (read-keyset 'doug)) @@ -103,7 +103,7 @@ (env-gaslog) (expect "Gas cost of querying an account's balance" - 12 (env-gas)) + 6 (env-gas)) ; account information checks out for new accounts (env-gas 0) (env-gaslog) @@ -114,7 +114,7 @@ (env-gaslog) (expect "Gas cost of querying the details of an account" - 13 (env-gas)) + 7 (env-gas)) (commit-tx) ;; credits + debits should succeed. Both should reflect the correct balance @@ -139,7 +139,7 @@ (env-gaslog) (expect "Gas cost of testing the DEBIT capability" - 14 (env-gas)) + 8 (env-gas)) ; debit tests (expect-failure @@ -407,7 +407,7 @@ (env-gaslog) (expect "Gas cost of transfer" - 185 (env-gas)) + 99 (env-gas)) (expect-failure "emily->doug capability used up" "TRANSFER exceeded" @@ -444,7 +444,7 @@ (transfer-create 'doug 'will (read-keyset 'will) 1.0)) (env-gaslog) (expect - "Gas cost of transfer-create" 171 (env-gas)) + "Gas cost of transfer-create" 93 (env-gas)) (expect "doug now has 0.4 coins" diff --git a/pact-tests/pact-tests/side-effects.repl b/pact-tests/pact-tests/side-effects.repl index b3739922..9b3ac5d8 100644 --- a/pact-tests/pact-tests/side-effects.repl +++ b/pact-tests/pact-tests/side-effects.repl @@ -53,11 +53,11 @@ (env-gaslimit 100000) (env-gas 0) (acquire-module-admin m) -(expect "Acquiring module admin gas cost evaluates enumerate" 63 (env-gas)) +(expect "Acquiring module admin gas cost evaluates enumerate" 52 (env-gas)) (acquire-module-admin m) ; Note: The gas cost here is: the flat cost of acquire-module-admin ; as a native + the gas from the previous test. In other words: ; this is testing that the only gas consumed is from the flat native cost, which means ; we didn't evaluate the cap twice -(expect "Acquiring module admin twice does not evaluate the cap twice" (+ 20 63) (env-gas)) +(expect "Acquiring module admin twice does not evaluate the cap twice" (+ 20 52) (env-gas)) (commit-tx) diff --git a/pact/Pact/Core/Gas/TableGasModel.hs b/pact/Pact/Core/Gas/TableGasModel.hs index 22d221ee..15dc87e2 100644 --- a/pact/Pact/Core/Gas/TableGasModel.hs +++ b/pact/Pact/Core/Gas/TableGasModel.hs @@ -25,17 +25,24 @@ import GHC.Base tableGasCostConfig :: GasCostConfig tableGasCostConfig = GasCostConfig - { _gcNativeBasicWork = 200 + -- The basic cost of entering the native table + + -- performing some work + { _gcNativeBasicWork = 100 , _gcFunctionArgumentCost = 25 , _gcMachineTickCost = 25 , _gcUnconsWork = 100 - , _gcReadPenalty = 4_500 - , _gcWritePenalty = 50_000 + , _gcReadPenalty = 2_500 + , _gcWritePenalty = 25_000 , _gcMetadataTxPenalty = 100_000 , _gcSelectPenalty = 40_000_000 , _gcConcatFactor = 100 - , _gcPerByteWriteCost = 200 - , _gcPerByteReadCost = 100 + -- Note: on a _really_ slow hard disk, it writes about + -- 80 bytes per microsecond, or 1 byte = 5 milligas after conversions + -- (80 bytes / 1 microsecond) * (2.5 micros / 1000 milligas) = 0.2 milligas per byte or 1 byte = 5 milligas + -- We add some extra overhead here, because we need to serialize and perform other checks. + , _gcPerByteWriteCost = 100 + -- Reads also tend to be about twice as fast as writes, so we charge a bit less + , _gcPerByteReadCost = 50 , _gcSortBytePenaltyReduction = 1000 , _gcPoseidonQuadraticGasFactor = 50_000 , _gcPoseidonLinearGasFactor = 38_000