Skip to content

Commit

Permalink
Remove parser for MlResult; fix Groth16 example
Browse files Browse the repository at this point in the history
  • Loading branch information
kwxm committed Mar 16, 2023
1 parent 885747e commit edfabad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
Expand Up @@ -287,9 +287,9 @@ groth16Verify alpha' beta' gamma' delta' abc1' abc2' a' b' c' s =
l1 = Tx.bls12_381_pairing a b
l2 = Tx.bls12_381_pairing alpha beta
l3 = Tx.bls12_381_pairing c delta
p = Tx.bls12_381_G1_add abc1 (Tx.bls12_381_G1_mul s abc2)
p = Tx.bls12_381_G1_add abc1 (Tx.bls12_381_G1_scalarMul s abc2)
l4 = Tx.bls12_381_pairing p gamma
y = Tx.bls12_381_GT_mul l2 (Tx.bls12_381_GT_mul l3 l4)
y = Tx.bls12_381_mulMlResult l2 (Tx.bls12_381_mulMlResult l3 l4)
in Tx.bls12_381_finalVerify l1 y

-- | Make a UPLC script applying groth16Verify to the inputs. Passing the
Expand Down
12 changes: 4 additions & 8 deletions plutus-core/plutus-core/src/PlutusCore/Parser/Builtin.hs
Expand Up @@ -8,7 +8,6 @@ import PlutusPrelude (Word8, reoption)

import PlutusCore.BLS12_381.G1 qualified as BLS12_381.G1
import PlutusCore.BLS12_381.G2 qualified as BLS12_381.G2
import PlutusCore.BLS12_381.Pairing qualified as BLS12_381.Pairing
import PlutusCore.Data
import PlutusCore.Default
import PlutusCore.Error (ParserError (InvalidData, UnknownBuiltinFunction))
Expand Down Expand Up @@ -99,20 +98,16 @@ conBLS12_381_G1_Element :: Parser BLS12_381.G1.Element
conBLS12_381_G1_Element = do
s <- con0xBS
case BLS12_381.G1.uncompress s of
Left err -> fail $ "Error decoding BLS12_381 G1 element: " ++ show err
Left err -> fail $ "Failed to decode value of type bls12_381_G1_element: " ++ show err
Right e -> pure e

conBLS12_381_G2_Element :: Parser BLS12_381.G2.Element
conBLS12_381_G2_Element = do
s <- con0xBS
case BLS12_381.G2.uncompress s of
Left err -> fail $ "Error decoding BLS12_381 G2 element: " ++ show err
Left err -> fail $ "Failed to decode value of type bls12_381_G2_element: " ++ show err
Right e -> pure e

conBLS12_381_MlResult :: Parser BLS12_381.Pairing.MlResult
conBLS12_381_MlResult = do
fail "Parsing BLS12_381GTElement is not supported"

-- | Parser for constants of the given type.
constantOf :: DefaultUni (Esc a) -> Parser a
constantOf uni = case uni of
Expand All @@ -127,7 +122,8 @@ constantOf uni = case uni of
DefaultUniData -> conData
DefaultUniBLS12_381_G1_Element -> conBLS12_381_G1_Element
DefaultUniBLS12_381_G2_Element -> conBLS12_381_G2_Element
DefaultUniBLS12_381_MlResult -> conBLS12_381_MlResult
DefaultUniBLS12_381_MlResult
-> error "Constants of type bls12_381_mlresult are not supported"

-- | Parser of constants whose type is in 'DefaultUni'.
constant :: Parser (Some (ValueOf DefaultUni))
Expand Down
3 changes: 1 addition & 2 deletions plutus-core/plutus-core/src/PlutusCore/Parser/Type.hs
Expand Up @@ -10,7 +10,6 @@ import PlutusPrelude
import PlutusCore.Annotation
import PlutusCore.BLS12_381.G1 as BLS12_381.G1
import PlutusCore.BLS12_381.G2 as BLS12_381.G2
import PlutusCore.BLS12_381.Pairing as BLS12_381.Pairing
import PlutusCore.Core.Type
import PlutusCore.Data
import PlutusCore.Default
Expand Down Expand Up @@ -121,6 +120,7 @@ defaultUniApplication = do
-- i.e. parse into @Tree Text@ and do the kind checking afterwards, but given that we'll still need
-- to do the kind checking of builtins regardless (even for UPLC), we don't win much by deferring
-- doing it.
-- We don't support constants of type bls12_381_mlresult, so there's no case for that.
defaultUni :: Parser (SomeTypeIn (Kinded DefaultUni))
defaultUni = choice $ map try
[ trailingWhitespace (inParens defaultUniApplication)
Expand All @@ -134,7 +134,6 @@ defaultUni = choice $ map try
, someType @_ @Data <$ symbol "data"
, someType @_ @BLS12_381.G1.Element <$ symbol "bls12_381_G1_element"
, someType @_ @BLS12_381.G2.Element <$ symbol "bls12_381_G2_element"
, someType @_ @BLS12_381.Pairing.MlResult <$ symbol "bls12_381_mlresult"
]

tyName :: Parser TyName
Expand Down

0 comments on commit edfabad

Please sign in to comment.