Skip to content

Commit

Permalink
Conformance tests for bitwise conversions (#5744)
Browse files Browse the repository at this point in the history
* Move conversion code into Plutus Core

* Documentation and notes on implementations

* Wrap implementations into builtins

* Properties as per CIP-0087

* CIP-0087 examples as tests

* Add new builtins to PlutusTx

* Document fromIntegral usage as a note

* Changelogs for CIP-0087 primitives

* Ensure conversions don't break on too-large arguments

* Ensure that conversions are available in V3

* Remove unnecessary pragmata on tests

* Fix overly-long test names, clarify test meaning in comments

* CIP link consistency

* Re-order integerToByteString arguments, avoid unnecessary padding

* Better documentation for implementations

* Correct properties for ByteStringToInteger

* Address feedback

* Integer/ByteString conversion costing experiments

* Turn off warning

* Turn off warning

* Initial costing for bitwise conversions

* Update print-cost-model; add some FIXMEs

* Update print-cost-model; add some FIXMEs

* Minor updates

* Fix typo

* Fix plugin; use byteStringToInteger in  bls12-318-costs

* Fix some tests

* Add generator for LiteralByteSize in plc evaluation tests

* Update parameter names in plutus-ledger-api

* Separate file for bitwise costing benchmarks

* More comprehensive exploratory costing benchmarks

* More comprehensive exploratory costing benchmarks

* Wrong test input sizes

* Correct costing benchmarks input widths

* One more benchmark

* All 0xFF benchmarks

* Wrong number

* Smaller bytetring inputs

* Try to keep CI happy

* Bigger benchmarks

* Another benchmarking run

* Fix modelling code for integer/bytestring conversions

* Remove experimental benchmarks; tidy up R code

* Tidying up; fix budget benchmarks for byteStringToInteger

* Move bitwise Convert module

* Move bitwise Convert module

* Update cost model

* Update bls12-381 cost test results

* Update comment

* Add changelog entries

* Remove accidentally-committed file

* Cost model tests for bitwise conversions

* Fix failing test

* Fix another failing test

* Address some small PR comments

* Address some small PR comments

* Initial conformance tests for bitwise conversion builtins

* Move size limit check back to Convert.hs and add some tests

* Move size limit check back to Convert.hs and add some tests

* Workaround for integerLog2 missing in GHC 8.10

* Workaround for integerLog2 missing in GHC 8.10

* Workaround for integerLog2 missing in GHC 8.10

* Add some more test cases

* More test cases

* More test cases

* More tests

* More test cases

* Formatting

* Test output mysteriously rearranged again

* Tidying up

---------

Co-authored-by: Koz Ross <[email protected]>
  • Loading branch information
kwxm and kozross authored Jan 26, 2024
1 parent 0c72941 commit 993c338
Show file tree
Hide file tree
Showing 34 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 0))
(program 1.0.0 (con integer 0))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 20016001699311))
(program 1.0.0 (con integer 20016001699311))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 0))
(program 1.0.0 (con integer 0))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bool True))
(program 1.0.0 (con bool True))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bool True))
(program 1.0.0 (con bool True))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 0))
(program 1.0.0 (con integer 0))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 263666621887506))
(program 1.0.0 (con integer 263666621887506))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con integer 0))
(program 1.0.0 (con integer 0))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bool True))
(program 1.0.0 (con bool True))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #123456abcdef))
(program 1.0.0 (con bytestring #123456abcdef))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #000000000000123456abcdef))
(program 1.0.0 (con bytestring #000000000000123456abcdef))

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Check that we can encode zero using the maximum width (8192).
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer 8192) (con integer 0)]
)
)

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer 20) (con integer -5)]
)

Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer -20) (con integer 5)]
)

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Check that trying to encode an integer to a bytestring usingn too narrow a width fails.
-- Check that trying to encode an integer to a bytestring using too narrow a width fails.
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer 5) (con integer 20016001699311)]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Check that a width greater than the maximum of 8192 is rejected when encoding zero.
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer 8193) (con integer 0)]
)
)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #000000000000000000000000))
(program 1.0.0 (con bytestring #000000000000000000000000))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #123456abcdef))
(program 1.0.0 (con bytestring #123456abcdef))

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- Negative inputs give an error
-- Negative inputs cause an error.
(program 1.0.0
[(builtin integerToByteString) (con bool True) (con integer 0) (con integer -5)]
)

Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #))
(program 1.0.0 (con bytestring #))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #efcdab563412))
(program 1.0.0 (con bytestring #efcdab563412))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #efcdab563412000000000000))
(program 1.0.0 (con bytestring #efcdab563412000000000000))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #000000000000000000000000))
(program 1.0.0 (con bytestring #000000000000000000000000))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Check that a particular bytestring decodes to the expected integer.
-- Check that a particular integer encodes to the expected bytestring.
(program 1.0.0
[(builtin integerToByteString) (con bool False) (con integer 0) (con integer 20016001699311)]
)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #efcdab563412))
(program 1.0.0 (con bytestring #efcdab563412))

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Negative inputs give an error
-- Negative inputs cause an error.
(program 1.0.0
[(builtin integerToByteString) (con bool False) (con integer 0) (con integer -5)]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(program 1.0.0 (con bytestring #))
(program 1.0.0 (con bytestring #))
5 changes: 2 additions & 3 deletions plutus-core/plutus-core/src/PlutusCore/Bitwise/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ integerToByteStringWrapper endiannessArg lengthArg input
emit "integerToByteString: negative length argument"
emit $ "Length requested: " <> (pack . show $ input)
evaluationFailure
-- Check that the requested length does not exceed the limit. *NB*: if we
-- remove the limit we'll still have to make sure that the length fits into an
-- Int.
-- Check that the requested length does not exceed the limit. *NB*: if we remove the limit we'll
-- still have to make sure that the length fits into an Int.
| lengthArg > integerToByteStringMaximumOutputLength = do
emit . pack $ "integerToByteString: requested length is too long (maximum is "
++ (show $ integerToByteStringMaximumOutputLength)
Expand Down
1 change: 0 additions & 1 deletion plutus-metatheory/plutus-metatheory.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cabal-version: 3.0
name: plutus-metatheory
version: 0.1.0.0
synopsis: Command line tool for running plutus core programs
homepage: https://github.com/input-output-hk/plutus
homepage: https://github.com/IntersectMBO/plutus
license: Apache-2.0
license-files:
Expand Down
2 changes: 1 addition & 1 deletion plutus-tx/src/PlutusTx/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ byteOrderToBool LittleEndian = False

-- | Convert a 'BuiltinInteger' into a 'BuiltinByteString', as described in
-- [CIP-0087](https://github.com/mlabs-haskell/CIPs/tree/koz/to-from-bytestring/CIP-XXXX).
-- The first argument indicated the endianness of the conversion and the third
-- The first argument indicates the endianness of the conversion and the third
-- argument is the integer to be converted, which must be non-negative. The
-- second argument must also be non-negative and it indicates the required width
-- of the output. If the width is zero then the output is the smallest
Expand Down

1 comment on commit 993c338

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Plutus Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.05.

Benchmark suite Current: 993c338 Previous: e3de827 Ratio
validation-auction_1-2 656.8 μs 618.2 μs 1.06
validation-auction_1-3 653.4 μs 616.9 μs 1.06
validation-auction_2-2 659.1 μs 620.9 μs 1.06
validation-auction_2-3 860.7 μs 810.3 μs 1.06
validation-auction_2-4 654 μs 615.9 μs 1.06
validation-currency-1 254.1 μs 240.8 μs 1.06
validation-escrow-redeem_2-1 405.5 μs 385.9 μs 1.05
validation-escrow-redeem_2-2 406.3 μs 386.8 μs 1.05
validation-escrow-redeem_2-3 406.3 μs 386.7 μs 1.05
validation-future-increase-margin-1 255.6 μs 241.7 μs 1.06
validation-future-increase-margin-2 546.4 μs 519.4 μs 1.05
validation-future-increase-margin-3 547.9 μs 519.1 μs 1.06
validation-future-increase-margin-4 499.5 μs 473.5 μs 1.05
validation-future-increase-margin-5 835.1 μs 786.6 μs 1.06
validation-future-pay-out-1 255.3 μs 241.2 μs 1.06
validation-future-pay-out-2 547.5 μs 517.3 μs 1.06
validation-future-pay-out-3 548.8 μs 519 μs 1.06
validation-future-pay-out-4 834.8 μs 787.9 μs 1.06
validation-future-settle-early-1 255.1 μs 241.2 μs 1.06
validation-future-settle-early-2 547.2 μs 520 μs 1.05
validation-future-settle-early-3 546.9 μs 519.3 μs 1.05
validation-future-settle-early-4 621.6 μs 588 μs 1.06
validation-game-sm-success_1-3 656.1 μs 620 μs 1.06
validation-game-sm-success_2-1 387.5 μs 368.9 μs 1.05
validation-game-sm-success_2-3 656 μs 619.4 μs 1.06
validation-game-sm-success_2-5 656.5 μs 620 μs 1.06
validation-multisig-sm-1 399.8 μs 379.3 μs 1.05
validation-multisig-sm-2 386.6 μs 368 μs 1.05
validation-multisig-sm-3 392.7 μs 373.8 μs 1.05
validation-multisig-sm-5 567.7 μs 535.5 μs 1.06
validation-multisig-sm-6 399.7 μs 379.8 μs 1.05
validation-multisig-sm-8 393.8 μs 374 μs 1.05
validation-multisig-sm-9 399.2 μs 377.2 μs 1.06
validation-multisig-sm-10 566.9 μs 535.9 μs 1.06
validation-ping-pong-1 331.2 μs 314.3 μs 1.05
validation-prism-2 413.7 μs 393.1 μs 1.05
validation-prism-3 372.3 μs 353.7 μs 1.05
validation-token-account-1 190.7 μs 181.5 μs 1.05
validation-uniswap-1 424.2 μs 397.1 μs 1.07
validation-uniswap-3 1785 μs 1694 μs 1.05
validation-uniswap-5 1170 μs 1113 μs 1.05
validation-vesting-1 350.8 μs 332.6 μs 1.05

This comment was automatically generated by workflow using github-action-benchmark.

CC: @input-output-hk/plutus-core

Please sign in to comment.