Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kwxm/costing/bitwise 4 #6301

Merged
merged 24 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 23 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
12 changes: 6 additions & 6 deletions plutus-benchmark/bls12-381-costs/bench/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ import Data.ByteString qualified as BS (empty)

benchHashAndAddG1 :: EvaluationContext -> Integer -> Benchmark
benchHashAndAddG1 ctx n =
let prog = mkHashAndAddG1Script (listOfSizedByteStrings n 4)
let prog = mkHashAndAddG1Script (listOfByteStringsOfLength n 4)
Copy link
Contributor

Choose a reason for hiding this comment

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

Great rename by the way.

in bench (show n) $ benchProgramCek ctx prog

benchHashAndAddG2 :: EvaluationContext -> Integer -> Benchmark
benchHashAndAddG2 ctx n =
let prog = mkHashAndAddG2Script (listOfSizedByteStrings n 4)
let prog = mkHashAndAddG2Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchUncompressAndAddG1 :: EvaluationContext -> Integer -> Benchmark
benchUncompressAndAddG1 ctx n =
let prog = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4)
let prog = mkUncompressAndAddG1Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchUncompressAndAddG2 :: EvaluationContext -> Integer -> Benchmark
benchUncompressAndAddG2 ctx n =
let prog = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4)
let prog = mkUncompressAndAddG2Script (listOfByteStringsOfLength n 4)
in bench (show n) $ benchProgramCek ctx prog

benchPairing :: EvaluationContext -> Benchmark
benchPairing ctx =
case listOfSizedByteStrings 4 4 of
case listOfByteStringsOfLength 4 4 of
[b1, b2, b3, b4] ->
let emptyDst = Tx.toBuiltin BS.empty
p1 = Tx.bls12_381_G1_hashToGroup (Tx.toBuiltin b1) emptyDst
Expand All @@ -46,7 +46,7 @@ benchPairing ctx =
q2 = Tx.bls12_381_G2_hashToGroup (Tx.toBuiltin b4) emptyDst
prog = mkPairingScript p1 p2 q1 q2
in bench "pairing" $ benchProgramCek ctx prog
_ -> error "Unexpected list returned by listOfSizedByteStrings"
_ -> error "Unexpected list returned by listOfByteStringsOfLength"

benchGroth16Verify :: EvaluationContext -> Benchmark
benchGroth16Verify ctx = bench "groth16Verify" $ benchProgramCek ctx mkGroth16VerifyScript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import Prelude (IO, mapM_)

printCosts_HashAndAddG1 :: Handle -> Integer -> IO ()
printCosts_HashAndAddG1 h n =
let script = mkHashAndAddG1Script (listOfSizedByteStrings n 4)
let script = mkHashAndAddG1Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_HashAndAddG2 :: Handle -> Integer -> IO ()
printCosts_HashAndAddG2 h n =
let script = mkHashAndAddG2Script (listOfSizedByteStrings n 4)
let script = mkHashAndAddG2Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_UncompressAndAddG1 :: Handle -> Integer -> IO ()
printCosts_UncompressAndAddG1 h n =
let script = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4)
let script = mkUncompressAndAddG1Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_UncompressAndAddG2 :: Handle -> Integer -> IO ()
printCosts_UncompressAndAddG2 h n =
let script = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4)
let script = mkUncompressAndAddG2Script (listOfByteStringsOfLength n 4)
in printSizeStatistics h (TestSize n) script

printCosts_Pairing :: Handle -> IO ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-}
module PlutusBenchmark.BLS12_381.Scripts
( checkGroth16Verify_Haskell
, listOfSizedByteStrings
, listOfByteStringsOfLength
, mkGroth16VerifyScript
, mkHashAndAddG1Script
, mkHashAndAddG2Script
Expand Down Expand Up @@ -61,9 +61,9 @@ import System.IO.Unsafe (unsafePerformIO)
import Prelude (fromIntegral)

-- Create a list containing n bytestrings of length l. This could be better.
{-# NOINLINE listOfSizedByteStrings #-}
listOfSizedByteStrings :: Integer -> Integer -> [ByteString]
listOfSizedByteStrings n l = unsafePerformIO . G.sample $
{-# NOINLINE listOfByteStringsOfLength #-}
listOfByteStringsOfLength :: Integer -> Integer -> [ByteString]
listOfByteStringsOfLength n l = unsafePerformIO . G.sample $
G.list (R.singleton $ fromIntegral n)
(G.bytes (R.singleton $ fromIntegral l))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ builtinHash :: BuiltinHashFun
builtinHash = Tx.sha2_256

-- Create a list containing n bytestrings of length l. This could be better.
{-# NOINLINE listOfSizedByteStrings #-}
listOfSizedByteStrings :: Integer -> Integer -> [ByteString]
listOfSizedByteStrings n l = unsafePerformIO . G.sample $
{-# NOINLINE listOfByteStringsOfLength #-}
listOfByteStringsOfLength :: Integer -> Integer -> [ByteString]
listOfByteStringsOfLength n l = unsafePerformIO . G.sample $
G.list (R.singleton $ fromIntegral n)
(G.bytes (R.singleton $ fromIntegral l))

Expand All @@ -94,7 +94,7 @@ mkInputs :: forall v msg .
mkInputs n toMsg hash =
Inputs $ map mkOneInput (zip seeds1 seeds2)
where seedSize = 128
(seeds1, seeds2) = splitAt n $ listOfSizedByteStrings (2*n) seedSize
(seeds1, seeds2) = splitAt n $ listOfByteStringsOfLength (2*n) seedSize
-- ^ Seeds for key generation. For some algorithms the seed has to be
-- a certain minimal size and there's a SeedBytesExhausted error if
-- it's not big enough; 128 is big enough for everything here though.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Added

- Added costing for the new bitwise builtins (see CIP-0058), which will probably become available at the Chang+1 HF.
Loading