<p>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.</p>

CC BY-SA 4.0
2021-05-27T08:39:18.560Z
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?
Johannes Sirsch
CC BY-SA 4.0
2021-05-26T19:40:26.953Z
2021-05-26T19:40:26.953Z
monolith
<p>The 'txSignedBy (scriptContextTxInfo ctx) pkh' takes the given PubKeyHash and checks the  txInfoSignatories.</p>
<p>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.</p>
<p>Check this github out, it is super helpful.</p>
<p><a href="https://github.com/input-output-hk/plutus/blob/d958880388c285e369abaeabea28952a78703441/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs" rel="nofollow noreferrer">https://github.com/input-output-hk/plutus/blob/d958880388c285e369abaeabea28952a78703441/plutus-ledger-api/src/Plutus/V1/Ledger/Contexts.hs</a></p>

CC BY-SA 4.0
2021-05-26T17:46:41.590Z
I know all that already. What prevents somebody to provide a wrong transaction signature?
Johannes Sirsch
CC BY-SA 4.0
2021-05-26T17:42:52.180Z
2021-05-26T17:42:52.180Z
Isaac Padberg
<p>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. <code>mkPolicy</code> isn't the minting policy but <code>mkPolicy pkh</code> is. So for each <code>PubKeyHash</code> you get a different minting policy script and therefore a different <code>CurrencySymbol</code>. So with your <code>PubKeyHash</code> you will only be able to mint tokens for your <code>CurrencySymbol</code> because the minting policy will only validate those transactions.</p>
<p>As for the <code>txInfoSignatories</code> in <code>TxInfo</code> in <code>ScriptContext</code>, this is what the docs say about it:</p>
<blockquote>
<p>Signatures provided with the transaction, attested that they all signed the tx</p>
</blockquote>
<p>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.</p>

CC BY-SA 4.0
2021-05-27T08:32:56.520Z
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.
Johannes Sirsch
CC BY-SA 4.0
2021-05-27T08:34:19.213Z
I'm wondering how a transaction is actually signed and why that can't be manipulated.
Johannes Sirsch
CC BY-SA 4.0
2021-05-27T16:48:28.603Z
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 https://www.youtube.com/watch?v=xIDL_akeras
Isaac Padberg
CC BY-SA 4.0
2021-05-27T19:08:15.010Z
If you want to know how it's done in Plutus right now check out validateTransaction (https://github.com/input-output-hk/plutus/blob/master/plutus-ledger/src/Ledger/Index.hs#L168) and follow checkValidInputs -> checkMatch -> signedBy (https://github.com/input-output-hk/plutus/blob/master/plutus-ledger-api/src/Plutus/V1/Ledger/Crypto.hs#L127).
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
CC BY-SA 4.0
2021-05-26T22:56:14.763Z
2021-05-26T22:56:14.763Z
tobxy123
<p>What prevents a bad user to provide a wrong <code>PubKeyHash</code> and sign it with a different signature in the <code>Signed.hs</code> example from the <a href="https://youtu.be/CTvOIusN_p8" rel="nofollow noreferrer">Plutus Pioneer Program NFT lecture</a>?</p>
<p>Policy:</p>
<pre><code>Policy:mkPolicy :: PubKeyHash -&gt; ScriptContext -&gt; Bool
mkPolicy pkh ctx = txSignedBy (scriptContextTxInfo ctx) pkh
</code></pre>
<p>Wallet-Code:</p>
<pre><code>pkh &lt;- pubKeyHash &lt;$&gt; Contract.ownPubKey
...
lookups = Constraints.monetaryPolicy $ policy pkh
</code></pre>
<p><strong>Couldn't he just use a different pkh and change the transaction signature to mint the token?<br>
What prevents that?</strong></p>
<p><strong>Update:</strong><br>
My question seems to lead people in the wrong directions, so to clarify:
<strong>I'm wondering how a transaction is actually signed and why that can't be manipulated.</strong></p>

CC BY-SA 4.0
2021-05-27T13:51:17.377Z
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.
Joshua Chia
CC BY-SA 4.0
2021-05-28T20:24:51.060Z
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. :)
Johannes Sirsch
<plutus-pioneer-program>
What prevents a bad user to provide a wrong signature to a transaction?
# What prevents a bad user to provide a wrong signature to a transaction?

(Asked by: username_0 on 2021-05-26)

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.

**Tags:** plutus-pioneer-program
> **Comments:**
> **username_1**: 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.  
> **username_0**: 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. :)  

---

## 3 answers

### Answer by username_2 on 2021-05-26. Score: 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.

> **Comments:**
> **username_0**: 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?  

---

### Answer by username_3 on 2021-05-26. Score: 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>

> **Comments:**
> **username_0**: I know all that already. What prevents somebody to provide a wrong transaction signature?  

---

### Answer by username_4 on 2021-05-26. Score: 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.

> **Comments:**
> **username_0**: 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.  
> **username_0**: I'm wondering how a transaction is actually signed and why that can't be manipulated.  
> **username_3**: 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 https://www.youtube.com/watch?v=xIDL_akeras  
> **username_4**: If you want to know how it's done in Plutus right now check out validateTransaction (https://github.com/input-output-hk/plutus/blob/master/plutus-ledger/src/Ledger/Index.hs#L168) and follow checkValidInputs -> checkMatch -> signedBy (https://github.com/input-output-hk/plutus/blob/master/plutus-ledger-api/src/Plutus/V1/Ledger/Crypto.hs#L127). 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.  

---

