Skip to content

Commit

Permalink
Make SizeOf incremental, add GasCostConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcardon committed Oct 14, 2024
1 parent d114e14 commit f2ddb47
Show file tree
Hide file tree
Showing 16 changed files with 669 additions and 981 deletions.
11 changes: 7 additions & 4 deletions pact-tests/Pact/Core/Test/SizeOfTests.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
-- | Tests for the sizes of various values.

module Pact.Core.Test.SizeOfTests where
Expand Down Expand Up @@ -35,10 +36,12 @@ tests = testGroup "SizeOfTests" $
assertEqual "size should be 5" 5 size
, testCase "PactValue1" $ do
Right size <- getSize SizeOfV0 (PInteger 1)
-- The size of the integer (at least 8 bytes) + the tag overhead of PLiteral (1 byte)
-- + tag overhead of PInteger (1 byte)
assertEqual "size should be 40" 10 size
, sizeOfSmallObject SizeOfV0 22
-- The size of a PLiteral (LInteger 1) should be
-- 2 bytes for the ADT of PactValue (header + tag)
-- 2 bytes for the ADT of Literal (header + tag)
-- The size of the integer (at least 8 bytes
assertEqual "size should be 40" 12 size
, sizeOfSmallObject SizeOfV0 25
]

getSize :: SizeOf a => SizeOfVersion -> a -> IO (Either PactErrorI Bytes)
Expand Down
90 changes: 45 additions & 45 deletions pact-tests/gas-goldens/builtinGas.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>=: 464
^: 536
abs: 200
acquire-module-admin: 291508
acquire-module-admin: 297894
add-time: 750
and?: 1128
at: 906
Expand All @@ -20,38 +20,38 @@ base64-encode: 311
bind: 677
ceiling: 400
chain-data: 500
compose-capability: 514515
compose-capability: 514500
compose: 4460
concat: 920
cond: 1202
contains: 605
continue: 444331
create-capability-guard: 229145
create-capability-pact-guard: 249303
create-module-guard: 188183
create-pact-guard: 211141
create-principal: 2102
create-table: 466487
continue: 441650
create-capability-guard: 227850
create-capability-pact-guard: 246800
create-module-guard: 188300
create-pact-guard: 210050
create-principal: 2302
create-table: 466600
days: 278
dec: 200
define-keyset: 8406
define-namespace: 43419
describe-keyset: 108406
describe-module: 264673
describe-namespace: 149136
describe-table: 566487
define-keyset: 8404
define-namespace: 44212
describe-keyset: 108404
describe-module: 262700
describe-namespace: 150124
describe-table: 566600
diff-time: 1414
distinct: 3176
drop: 1400
emit-event: 264965
enforce-guard: 3366
enforce-keyset: 3366
emit-event: 263650
enforce-guard: 3566
enforce-keyset: 3566
enforce-verifier: 10150
enumerate: 827
enumerate: 824
exp: 10000
filter: 4460
floor: 400
fold-db: 40524992
fold-db: 40525850
fold: 1490
format-time: 1041
format: 2000
Expand All @@ -61,47 +61,47 @@ hyperlane-decode-token-message: 2175
hyperlane-encode-token-message: 2475
hyperlane-message-id: 2743
identity: 200
insert: 524792
install-capability: 667102
insert: 525650
install-capability: 670489
int-to-str: 1000
is-charset: 1788
is-principal: 797
keys: 40524792
keyset-ref-guard: 10427
keys: 40525650
keyset-ref-guard: 10425
length: 1101
list-modules: 100000
ln: 12000
log: 6000
make-list: 216
make-list: 225
map: 1715
minutes: 276
mod: 200
namespace: 43431
namespace: 44224
negate: 200
not: 664
not?: 664
or?: 664
pact-id: 227047
pairing-check: 11807943
pact-id: 225950
pairing-check: 12009033
parse-time: 602
point-add: 5600
poseidon-hash-hack-a-chain: 6393700
read-decimal: 303
read-integer: 303
read-keyset: 8610
read-msg: 303
read-string: 303
read: 533297
read-decimal: 503
read-integer: 503
read-keyset: 8808
read-msg: 503
read-string: 503
read: 534550
remove: 460
require-capability: 403423
resume: 507573
require-capability: 402750
resume: 515531
reverse: 800
round: 400
scalar-mult: 360400
select: 40524942
select: 40525800
shift: 1070
show: 1201
sort: 1403
show: 1400
sort: 1400
sqrt: 12000
str-to-int: 708
str-to-list: 751
Expand All @@ -110,14 +110,14 @@ time: 500
tx-hash: 200
typeof-principal: 997
typeof: 200
update: 633197
validate-principal: 4140
update: 634750
validate-principal: 4540
where: 2340
with-default-read: 538763
with-read: 533580
write: 524792
with-default-read: 540016
with-read: 534833
write: 525650
xor: 500
yield: 328698
yield: 328150
zip: 4920
|: 500
~: 250
4 changes: 2 additions & 2 deletions pact-tests/pact-tests/coin-v5.repl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
(env-gaslog)
(expect
"Gas cost of loading fungible contract"
958 (env-gas))
918 (env-gas))
(commit-tx)

(env-gasmodel "table")
Expand All @@ -18,7 +18,7 @@
(env-gaslog)
(expect
"Gas cost of loading fungible-xchain contract"
389 (env-gas))
371 (env-gas))
(commit-tx)
(begin-tx)
(env-gas 0)
Expand Down
1 change: 1 addition & 0 deletions pact-tng.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ library
Pact.Core.SPV
Pact.Core.Repl
Pact.Core.SizeOf
Pact.Core.SizeOf.Deriving
Pact.Core.StackFrame
Pact.Core.Legacy.LegacyCodec
Pact.Core.Verifiers
Expand Down
Loading

0 comments on commit f2ddb47

Please sign in to comment.