5

What prevents a bad user to provide a wrong PubKeyHash and sign it with a different signature in the Signed.hs example from the Plutus Pioneer Program NFT lecture?

Policy:

Policy:mkPolicy :: PubKeyHash -> ScriptContext -> Bool
mkPolicy pkh ctx = txSignedBy (scriptContextTxInfo ctx) pkh

Wallet-Code:

pkh <- pubKeyHash <$> Contract.ownPubKey
...
lookups = Constraints.monetaryPolicy $ policy pkh

Couldn't he just use a different pkh and change the transaction signature to mint the token?
What prevents that?

Update:
My question seems to lead people in the wrong directions, so to clarify: I'm wondering how a transaction is actually signed and why that can't be manipulated.

2
  • I think your question will be clearer if you don't require readers to watch a video that is > 1 hour to get the necessary context. You could include the necessary context in your question and make references to the video unnecessary. May 27, 2021 at 13:51
  • The video is actually not that important. It just provides a good example for signature checking. As already multiple times stated: I'm just wondering why signatures can't be manipulated and how that is working. But thanks for your feedback. :) May 28, 2021 at 20:24

3 Answers 3

1

I don't know the specifics, but I believe under the hood the corresponding private key is used to sign the transaction and the public key is used for verification. So you cannot use any other public key, since you do not know the corresponding private key.

1
  • I'm no cryptographic expert. That answer goes in the right direction. Would be great if someone could extend it. I suspect that a private key is sent around because then it could be stolen, right? May 27, 2021 at 8:39
0

The 'txSignedBy (scriptContextTxInfo ctx) pkh' takes the given PubKeyHash and checks the txInfoSignatories.

If the provided PubKeyHash is in the signatory, it will validate. The only way for that specific PubKeyHash to be in the signatory is if it is the original creator of the validation script. So only the original creator can validate this contract.

Check this github out, it is super helpful.

https://github.com/input-output-hk/plutus/blob/d958880388c285e369abaeabea28952a78703441/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs

1
  • I know all that already. What prevents somebody to provide a wrong transaction signature? May 26, 2021 at 17:46
0

The policy can indeed be used by anyone to mint their tokens. However the actual minting policy script is dependent on the PubKeyHash, i.e. mkPolicy isn't the minting policy but mkPolicy pkh is. So for each PubKeyHash you get a different minting policy script and therefore a different CurrencySymbol. So with your PubKeyHash you will only be able to mint tokens for your CurrencySymbol because the minting policy will only validate those transactions.

As for the txInfoSignatories in TxInfo in ScriptContext, this is what the docs say about it:

Signatures provided with the transaction, attested that they all signed the tx

I'm assuming that checking the transaction signatures won't be done by the Plutus code itself once it's been integrated into the Cardano node. That is because validating transaction signatures is a very basic check that every blockchain node has to do anyways.

4
  • The first part is clear to me. It is well explained in the lecture. I'm relatively sure that the signature will be checked within the Plutus Core code on-chain since it is compiled to that. May 27, 2021 at 8:32
  • I'm wondering how a transaction is actually signed and why that can't be manipulated. May 27, 2021 at 8:34
  • 1
    Transactions are signed using the signers private key. It is then legitimized by taking the signed transaction and the public key of the signer, and doing some cryptographic magic to determine if signer of the transaction also had access to the private key behind the public key. Watch this video youtube.com/watch?v=xIDL_akeras May 27, 2021 at 16:48
  • If you want to know how it's done in Plutus right now check out validateTransaction (github.com/input-output-hk/plutus/blob/master/plutus-ledger/src/…) and follow checkValidInputs -> checkMatch -> signedBy (github.com/input-output-hk/plutus/blob/master/plutus-ledger-api/…). Keep in mind that once Alonzo goes live Plutus will be integrated to the Cardano node (github.com/input-output-hk/cardano-node) which provides the actual executable. So far when working with Plutus we are just using a blockchain Emulator.
    – tobxy123
    May 27, 2021 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.