IntersectMBO / plutus-apps

The Plutus application platform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

verifySignedMessageConstraints does not work

volodyad opened this issue · comments

Is there an existing issue for this?

  • I have searched the existing issues

Summary

Use next code to sign and verify message

main :: IO ()
main = do
  args <- getArgs
  let nargs = length args
  let gameId = if nargs > 0 then read (args!!0) else 0
  let oracleSignKey = if nargs > 1 then args!!1  else ""
  let winnerId = if nargs > 2 then read (args!!2) else 0
  let statusM = if nargs > 3 then decode (LB8.pack $ args!!3) else Just NS
  status <- maybe(exitWithErrorMessage "Wrong status") pure statusM
  signerKeyEither:: Either (FileError TextEnvelopeError) (SigningKey PaymentExtendedKey)<- readFileTextEnvelope (AsSigningKey AsPaymentExtendedKey) oracleSignKey

  case signerKeyEither of
    Left err -> exitWithErrorMessage $ "SKey parse error" ++ show err
    Right sKey -> do
      let signKeyE = xprv $ serialiseToRawBytes sKey
      case signKeyE of 
        Left error -> exitWithErrorMessage error
        Right signKey -> do
          let privPub = toPublicKey signKey
          let pkhPriv = pubKeyHash $ privPub

          --exitWithErrorMessage $ "pkh: " ++ show pkh ++ " privPkh: " ++ show pkhPriv
          let message = OracleSignedMessage{
              osmWinnerId = winnerId,
              osmGameId = gameId,
              osmGameStatus = status
          }
          let signedMessage = signMessage message signKey

          case verifySignedMessageConstraints privPub signedMessage of
            Left err                 -> exitWithErrorMessage $ "verify error: " ++ show err
            Right (osm, constraints) -> exitWithErrorMessage $ "verify success" 


exitWithErrorMessage :: String -> IO a
exitWithErrorMessage str = hPutStrLn stderr str >> exitWith (ExitFailure 1)

Steps to reproduce the behavior

create extended key and run

{
    "type": "PaymentExtendedSigningKeyShelley_ed25519_bip32",
    "description": "Payment Signing Key",
    "cborHex": "..."
}

exec command
cabal exec -- encode-oracle-request 1 $ORACLE_SIGN_KEY 0 "\"LIVE\""

Actual Result

Output
verify error: SignatureMismatch e4eeb82e5992083a4fb18ff97fe490e75978e3e8d3f51fd8e0a958ae9e1f7fce88050409f868cd2eae77c6f836aadc76dcb42d2c2a145105b62394c0e1469f09 3978ed863054ad729479fcee093506e3cdca0ed71cf2aa24b6fd62f5c56e4cb9 9a23ef09426b07ac1ba4a70b5dea0493235f2bff1ae6a2fcfc6de765adfa6079

Expected Result

It should verify signature successfully

What have you tried to resolve this issue?

Dived to the sign verifiction, but do not know yet much detils of compaibility XPrv with Ed25519Donna

module Crypto (verifySignature) where

import Control.Applicative
import Crypto.ECC.Ed25519Donna
import Crypto.Error (maybeCryptoError)
import Data.ByteString qualified as BS

verifySignature
    :: Alternative f
    => BS.ByteString  -- ^ Public Key
    -> BS.ByteString  -- ^ Message
    -> BS.ByteString  -- ^ Signature
    -> f Bool
verifySignature pubKey msg sig =
    maybe empty pure . maybeCryptoError $
        verify
            <$> publicKey pubKey
            <*> pure msg
            <*> signature sig

Checked our docs?

  • Yes, I have looked in the the readme, plutus docs, and technical report for help on this issue.

Checked Stack Exchange?

  • Yes, I have searched Stack Exchange for this issue and it doesn't exist.
  • I have considered raising this issue in Stack Exchange.

System info

plutus apps a78e858
nix on macos bigSur 11.5.2

Screenshots and attachments

No response

Hey @volodyad we will investigate this issue to try and discern why this isn't working for you.

It turns out the issue was that there was a passphrase always being used with the oracle signing functions that didn't necessarily correspond to private keys like the one you loaded from the text envelope, I have created PR to address this.

Fixed with #177