-
Notifications
You must be signed in to change notification settings - Fork 479
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/bls12-381/prototype (PLT-192, PLT-1557, PLT-1554, etc). #5231
Changes from 170 commits
0020b29
7e0de43
3927e15
4ade080
56589d9
a592101
26b01ec
1bb2753
099ba8c
bf30d3f
4956ed9
b1b1b0d
2354352
a81447e
3cfe6db
51bbb93
dd3b6d3
48a0f18
aaa8ec9
378264f
39d1804
236b2cb
c977559
0b0048e
c17d0b8
cd8c1c5
994b478
fd18459
1c219e7
ba59233
1a18aff
7e812f2
6216a1a
b102e4a
54087c7
b337f23
196f6ac
a1e1c48
00c48ee
c276129
5b4a6fb
d5c5660
c292e0e
aaf2abc
e75b9a2
8de27a1
4d43ca9
fdf8f6f
c3bea5f
640fdd7
9365d43
2ae1323
4b22cbe
fd8f5c0
05a9f37
a5c5386
384add7
fa3ae48
b9ba88c
0f25b60
3a13bbc
0b854bd
8041694
bc76516
5f5f705
7ef1fe1
8d67d51
efd3d1f
40b55ae
52c8d63
0242dd3
9a761c2
b8c0a95
5cd1e06
cbde413
4d4280d
086b83a
ffe0130
94176b7
a4140ff
d423a47
1963ff8
251ef9c
9cc3f61
e451055
fa4b195
82237c5
fc02f08
885747e
edfabad
7771982
f1581d5
fa29bc1
e17860c
80db5e7
2a2659e
8385fbf
0370055
06d78c1
575f35d
616608c
73a3278
067b444
e0bd999
3d89f5d
9affbaa
d238be1
b8d6690
37321b8
8d5080e
eda34de
2ffe630
aeaec35
ea3064b
51b244f
82e659a
5acda2d
98caea1
de4ca72
a91d8a3
9a2e840
79bdd9e
c67dda5
4521caf
9c6b92a
2319ad0
311d000
18cf9f6
6585a98
0e1c8c5
5dfd770
02d6bf3
fe45053
6cc73e3
6d969d8
a89677e
bf07f99
f25bceb
930f578
dfbf702
5292de0
2038ca0
1c182de
b0c8f7f
6916df4
100f301
8c74593
50d0e93
a520986
6f0698a
a71be07
483cdcd
a077b9d
ce46a04
1187e3f
9316d19
228de87
17f6a86
a345dc7
00e0be0
6970cbd
3a7ed24
f121dd6
8957ee1
d83721a
5fa04f5
50e5040
c1191cb
5fc950c
6630d15
45ff422
16bf911
c9fd616
f2294bc
18f28a0
7f897b8
1ac1ae6
332773f
8b0db0b
aed2c6c
ccdac92
2b1b382
10c5e47
1f93366
4aee59e
bb5b70b
9f1ccb6
4360585
610ee51
2bae2c7
748b666
8f9b2d7
0460f4e
bf30c36
fa8b323
d71023e
5f136e7
2920bc5
f408615
fe62965
513f4e6
eed55b5
4f94d7f
946ee31
2b9ac9f
af2e99d
e5bfc61
2c733ab
85ec23d
b3eb0f3
3a859cc
3d10333
7daa1d5
198816d
0e97668
2b0f142
75c8cfe
19563fa
651f525
aa41b37
310cfe0
57dc567
fcc4551
9a07a5a
e88aa44
17ff8f3
df8f19b
e67e029
29a78e3
646b7e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,10 @@ let | |
|
||
inputMap = { "https://input-output-hk.github.io/cardano-haskell-packages" = inputs.CHaP; }; | ||
# No source-repository-packages right now | ||
sha256map = { }; | ||
sha256map = { | ||
"https://github.com/input-output-hk/cardano-base"."56a71b150b7ff7fb6d6bf588f3e9d88822c9048c" = | ||
"sha256-mTRYnpjNATU8W9th9KTNDairJDnFiq12E58t6evHMD8"; | ||
}; | ||
|
||
# TODO: move this into the cabal.project using the new conditional support? | ||
# Configuration settings needed for cabal configure to work when cross compiling | ||
|
@@ -156,6 +159,7 @@ let | |
cardano-crypto-class.components.library.pkgconfig = lib.mkForce [ | ||
[ pkgs.libsodium-vrf pkgs.secp256k1 ] | ||
]; | ||
cardano-crypto-class.components.library.libs = lib.mkForce [ pkgs.blst ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives you warnings about a missing dynamic library, which is misleading because it's a static library and it isn't missing. I've asked our nix experts and they think there might be something genuinely wrong here. It's not clear how to resolve this: maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does nothing at the moment, right? Since we're not using the code from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, since we're vendoring things into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, this is for the The stuff in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, I think I see what you mean now. It does look as if that line refers to something that doesn't currently exist, but I think that without it you can't build this branch. Could you try building it with and without that line and see what happens? I made that modification after the discussion on Slack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pkg-config logic should be in the most recent iohk-nix. |
||
}; | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
-- editorconfig-checker-disable-file | ||
{- | Plutus benchmarks measuring actual execution times of some BSL12-381 | ||
operations, mainly intended to give us an idea of what we can do within the | ||
on-chain execution limits. -} | ||
module Main where | ||
|
||
import Criterion.Main | ||
|
||
import PlutusBenchmark.BLS12_381.Common | ||
import PlutusBenchmark.Common (benchTermCek) | ||
import PlutusTx.Prelude qualified as Tx | ||
import UntypedPlutusCore qualified as UPLC | ||
|
||
benchProgCek :: UProg -> Benchmarkable | ||
benchProgCek (UPLC.Program _ _ t) = benchTermCek t | ||
|
||
benchHashAndAddG1 :: Integer -> Benchmark | ||
benchHashAndAddG1 n = | ||
let prog = mkHashAndAddG1Script (listOfSizedByteStrings n 4) | ||
in bench (show n) $ benchProgCek prog | ||
effectfully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
benchHashAndAddG2 :: Integer -> Benchmark | ||
benchHashAndAddG2 n = | ||
let prog = mkHashAndAddG2Script (listOfSizedByteStrings n 4) | ||
in bench (show n) $ benchProgCek prog | ||
effectfully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
benchUncompressAndAddG1 :: Integer -> Benchmark | ||
benchUncompressAndAddG1 n = | ||
let prog = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4) | ||
in bench (show n) $ benchProgCek prog | ||
|
||
benchUncompressAndAddG2 :: Integer -> Benchmark | ||
benchUncompressAndAddG2 n = | ||
let prog = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4) | ||
in bench (show n) $ benchProgCek prog | ||
|
||
benchPairing :: Benchmark | ||
benchPairing = | ||
case listOfSizedByteStrings 4 4 of | ||
[b1, b2, b3, b4] -> | ||
let p1 = Tx.bls12_381_G1_hashToGroup $ Tx.toBuiltin b1 | ||
p2 = Tx.bls12_381_G2_hashToGroup $ Tx.toBuiltin b2 | ||
q1 = Tx.bls12_381_G1_hashToGroup $ Tx.toBuiltin b3 | ||
q2 = Tx.bls12_381_G2_hashToGroup $ Tx.toBuiltin b4 | ||
prog = mkPairingScript p1 p2 q1 q2 | ||
in bench "pairing" $ benchProgCek prog | ||
_ -> error "Unexpected list returned by listOfSizedByteStrings" | ||
|
||
benchGroth16Verify :: Benchmark | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should also add some budget tests for these so we can see how much they end up costing deterministically? |
||
benchGroth16Verify = bench "groth16Verify" $ benchProgCek mkGroth16VerifyScript | ||
|
||
main :: IO () | ||
main = do | ||
defaultMain [ | ||
bgroup "hashAndAddG1" $ fmap benchHashAndAddG1 [0, 10..150] | ||
, bgroup "hashAndAddG2" $ fmap benchHashAndAddG2 [0, 10..150] | ||
, bgroup "uncompressAndAddG1" $ fmap benchUncompressAndAddG1 [0, 10..150] | ||
, bgroup "uncompressAndAddG2" $ fmap benchUncompressAndAddG2 [0, 10..150] | ||
, benchPairing | ||
, benchGroth16Verify | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
-- editorconfig-checker-disable-file | ||
{-# LANGUAGE NumericUnderscores #-} | ||
{-# OPTIONS_GHC -Wno-unused-top-binds #-} | ||
{-# OPTIONS_GHC -Wno-name-shadowing #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do w need to turn these off? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Apparently not. Maybe left over from earlier experiments. |
||
|
||
{- | Print out the costs of various test scripts involving the BLS12_381 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so I think what I'm suggesting is basically to make this into a test suite with budget tests instead. Maybe the output is less easy to read, IDK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also check in the output as a golden file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Big 👍 from me on that. |
||
primitives. Most of these work on varying numbers of inputs so that we can | ||
get an idea of what we can do within the on-chain execution limits. | ||
-} | ||
module Main (main) | ||
|
||
where | ||
|
||
import PlutusBenchmark.BLS12_381.Common | ||
|
||
import PlutusCore.Evaluation.Machine.ExBudget (ExBudget (exBudgetCPU, exBudgetMemory)) | ||
import PlutusCore.Evaluation.Machine.ExBudgetingDefaults qualified as PLC | ||
import PlutusCore.Evaluation.Machine.ExMemory (ExCPU (..), ExMemory (..)) | ||
import PlutusTx.Prelude as Tx hiding (sort, (*)) | ||
import UntypedPlutusCore qualified as UPLC | ||
import UntypedPlutusCore.Evaluation.Machine.Cek qualified as Cek | ||
|
||
import Data.ByteString qualified as BS | ||
import Flat qualified | ||
import Text.Printf (printf) | ||
|
||
import Prelude (Double, IO, Integral, String, fromIntegral, mapM_, show, (*), (/)) | ||
|
||
-- Protocol parameters (November 2022) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is duplicated from somewhere else, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grumble |
||
|
||
-- | This is the "maximum transaction size". We're just comparing the size of | ||
-- the script with this, so our results may be a little optimistic if the | ||
-- transaction includes other stuff (I'm not sure exactly what "maximum | ||
-- transaction size" means). | ||
max_tx_size :: Integer | ||
max_tx_size = 16384 | ||
|
||
max_tx_ex_steps :: Integer | ||
max_tx_ex_steps = 10_000_000_000 | ||
|
||
max_tx_ex_mem :: Integer | ||
max_tx_ex_mem = 14_000_000 | ||
|
||
-------------------------------- Printing -------------------------------- | ||
|
||
-- Printing utilities | ||
percentage :: (Integral a, Integral b) => a -> b -> Double | ||
percentage a b = | ||
let a' = fromIntegral a :: Double | ||
b' = fromIntegral b :: Double | ||
in (a'/b' * 100) | ||
effectfully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
percentTxt :: (Integral a, Integral b) => a -> b -> String | ||
percentTxt a b = printf "(%.1f%%)" (percentage a b) | ||
|
||
-- | Evaluate a script and return the CPU and memory costs (according to the cost model) | ||
evaluate :: UProg -> (Integer, Integer) | ||
evaluate (UPLC.Program _ _ prog) = | ||
case Cek.runCekDeBruijn PLC.defaultCekParameters Cek.tallying Cek.noEmitter prog of | ||
(_res, Cek.TallyingSt _ budget, _logs) -> | ||
let ExCPU cpu = exBudgetCPU budget | ||
ExMemory mem = exBudgetMemory budget | ||
in (fromIntegral cpu, fromIntegral mem) | ||
|
||
-- | Evaluate a script and print out the serialised size and the CPU and memory | ||
-- usage, both as absolute values and percentages of the maxima specified in the | ||
-- protocol parameters. | ||
printStatistics :: Integer -> UProg -> IO () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, this is very similar to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still wondering about the budget tests |
||
printStatistics n script = do | ||
let serialised = Flat.flat (UPLC.UnrestrictedProgram $ toAnonDeBruijnProg script) | ||
size = BS.length serialised | ||
(cpu, mem) = evaluate script | ||
-- BS.writeFile "output" serialised | ||
-- printf "%s\n" $ show $ PP.prettyClassicDebug script | ||
printf " %3s %7d %8s %15d %8s %15d %8s \n" | ||
(if n > 0 then show n else "-") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make it |
||
size (percentTxt size max_tx_size) | ||
cpu (percentTxt cpu max_tx_ex_steps) | ||
mem (percentTxt mem max_tx_ex_mem) | ||
|
||
------------------------------- Examples --------------------------------- | ||
|
||
printCosts_HashAndAddG1 :: Integer -> IO () | ||
printCosts_HashAndAddG1 n = | ||
let script = mkHashAndAddG1Script (listOfSizedByteStrings n 4) | ||
in printStatistics n script | ||
|
||
|
||
printCosts_HashAndAddG2 :: Integer -> IO () | ||
printCosts_HashAndAddG2 n = | ||
let script = mkHashAndAddG2Script (listOfSizedByteStrings n 4) | ||
in printStatistics n script | ||
|
||
|
||
printCosts_UncompressAndAddG1 :: Integer -> IO () | ||
printCosts_UncompressAndAddG1 n = | ||
let script = mkUncompressAndAddG1Script (listOfSizedByteStrings n 4) | ||
in printStatistics n script | ||
|
||
printCosts_UncompressAndAddG2 :: Integer -> IO () | ||
printCosts_UncompressAndAddG2 n = | ||
let script = mkUncompressAndAddG2Script (listOfSizedByteStrings n 4) | ||
in printStatistics n script | ||
|
||
printCosts_Pairing :: IO () | ||
printCosts_Pairing = do | ||
let p1 = Tx.bls12_381_G1_hashToGroup $ toBuiltin $ BS.pack [0x23, 0x43, 0x56, 0xf2] | ||
p2 = Tx.bls12_381_G2_hashToGroup $ toBuiltin $ BS.pack [0x10, 0x00, 0xff, 0x88] | ||
q1 = Tx.bls12_381_G1_hashToGroup $ toBuiltin $ BS.pack [0x11, 0x22, 0x33, 0x44] | ||
q2 = Tx.bls12_381_G2_hashToGroup $ toBuiltin $ BS.pack [0xa0, 0xb1, 0xc2, 0xd3] | ||
script = mkPairingScript p1 p2 q1 q2 | ||
printStatistics (-1) script | ||
|
||
printCosts_Groth16Verify :: IO () | ||
printCosts_Groth16Verify = do | ||
let script = mkGroth16VerifyScript | ||
printStatistics (-1) script | ||
|
||
printHeader :: IO () | ||
printHeader = do | ||
printf " n script size CPU usage Memory usage\n" | ||
printf " ----------------------------------------------------------------------\n" | ||
|
||
main :: IO () | ||
main = do | ||
|
||
printf "Hash n bytestrings onto G1 and add points\n\n" | ||
printHeader | ||
mapM_ printCosts_HashAndAddG1 [0, 10..150] | ||
printf "\n\n" | ||
|
||
printf "Hash n bytestrings onto G2 and add points\n\n" | ||
printHeader | ||
mapM_ printCosts_HashAndAddG2 [0, 10..150] | ||
printf "\n\n" | ||
|
||
printf "Uncompress n G1 points and add the results\n\n" | ||
printHeader | ||
mapM_ printCosts_UncompressAndAddG1 [0, 10..150] | ||
printf "\n\n" | ||
|
||
printf "Uncompress n G2 points and add the results\n\n" | ||
printHeader | ||
mapM_ printCosts_UncompressAndAddG2 [0, 10..150] | ||
printf "\n\n" | ||
|
||
printf "Apply pairing to two pairs of points in G1 x G2 and run finalVerify on the results\n\n" | ||
printHeader | ||
printCosts_Pairing | ||
printf "\n\n" | ||
|
||
printf "Groth16 verification example\n\n" | ||
printHeader | ||
printCosts_Groth16Verify | ||
printf "\n" | ||
|
||
if checkGroth16Verify_Haskell | ||
then printf "Groth16Verify succeeded\n" | ||
else printf "Groth16Verify failed\n" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who's making sure this happens? Inigo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please get this into CHaP, before we add SRPs again? Chap is under our control. @lehins, I believe you are currenlty in charge of cardano-base or am I mistaken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we're not going to merge this with a s-r-p. Doing this for a pre-release is fine though.