<p>Actually, This is an interesting question. I would like to share my thought about this. I don't know if I made mistakes somewhere. Please just consider it as a reference.</p>
<p><strong>Problem:</strong></p>
<p>we want to consume all UTxOs locked at a validator address without knowing the validator script or without qualifying it.</p>
<p><strong>Approach:</strong></p>
<p>we could try to create our malicious script that <strong>always returns to True</strong>. However, Cardano will always check if the hash value of the actual script is the same as the hash value of the provided script when we submit the consuming transaction. So in our malicious script, we could add a random line such as nonce = 1, nonce = 2, nonce = 3 and so on until the hash value of our script is the same as the actual script.</p>
<p><strong>My calculation:</strong></p>
<p>As far as I know, the validator address is also the hash value of the script. I tried to take a sample validator address which is from plutus-pioneer-program (see <a href="https://github.com/input-output-hk/plutus-pioneer-program/blob/044fa5d026a0d5f34ce6acb71d444e7d444fe125/code/Week02/assets/gift.addr" rel="nofollow noreferrer">here</a>), it seems to be the shortest address type. <em>addr_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla</em>. although I am not sure how the hash function is implemented, I can see all characters could be 0-9 or a-z and the length of the address <em>1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla</em> is 54. Based on this idea, I calculated the number of all possible cases of the hash value as the following</p>
<p>Total possible cases = (10 + 26) <sup> 54 </sup> cases</p>
<p>Where</p>
<ul>
<li>10 is for 0-9</li>
<li>26 is for a-z</li>
<li>54 is the length of the address (is also the length of the hash value of the validator).</li>
</ul>
<p>I am not really sure about the speed of today's CPU. let's say that 8 CPUs could handle 10^9 check (including compiling and running the malicious programs to take the hash value and check if it's expected) per second.</p>
<p>the result will be: (10+26) <sup> 54 </sup> / 10<sup>9</sup> / 3600 / 24 / 365 ~ <strong>3.48 * 10 <sup> 67 </sup> years</strong>.</p>
<p>It's a rough estimation, that's possible to have the case that some nonce value lead to the same hash value. for instance, nonce = 1 and nonce = 123978231231 return the same hash value, we need to check even more. Otherwise, in case we could find the result during the checking process soon, we don't need that long time.</p>
<p>Hope this is helpful!</p>

CC BY-SA 4.0
2023-04-18T15:31:06.200Z
2023-04-18T15:31:06.200Z
manhdt
<p>what is preventing an adversary to find (in many hours) a nonce that would make a malicious validator script to have the same hash and address of my validator script, and then submit it with cardano-cli in a transaction that unlocks at once all the utxos held at that address? Would this take (in average) a year with 8 or 16 of today's CPUs? 10 years? 1000 years?</p>

CC BY-SA 4.0
2023-04-11T01:54:52.210Z
Can you share more information about what you are trying to do?
Falcon Stakepool
CC BY-SA 4.0
2023-04-11T01:55:08.583Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
CC BY-SA 4.0
2023-04-12T12:42:42.310Z
By adding a constant to a malicious script (let's call this constant "nonce") and by changing its value, one can obtain a different hash for the malicious script and so after many different attempts, can find a value for nonce such that the malicious script has the same hash (and address) of my genuine validator. If I originally provided only the hash of my validator and not the script itself, then one could in theory substitute it with the malicious script and override my genuine validator. So the question is:
Quantinity
CC BY-SA 4.0
2023-04-12T12:42:49.357Z
how long could it take in average to a computer with 16 of today's CPUs, given a malicious script,  to find a nonce such that the hash and the address of the malicious script is the same hash and address of my genuine validator?
Quantinity
<script><validator><hash><attacks>
Creating a malicious validator script whose hash equals that of an existing validator script
# Creating a malicious validator script whose hash equals that of an existing validator script

(Asked by: username_0 on 2023-04-08)

what is preventing an adversary to find (in many hours) a nonce that would make a malicious validator script to have the same hash and address of my validator script, and then submit it with cardano-cli in a transaction that unlocks at once all the utxos held at that address? Would this take (in average) a year with 8 or 16 of today's CPUs? 10 years? 1000 years?

**Tags:** script, validator, hash, attacks
> **Comments:**
> **username_1**: Can you share more information about what you are trying to do?  
> **username_2**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
> **username_0**: By adding a constant to a malicious script (let's call this constant "nonce") and by changing its value, one can obtain a different hash for the malicious script and so after many different attempts, can find a value for nonce such that the malicious script has the same hash (and address) of my genuine validator. If I originally provided only the hash of my validator and not the script itself, then one could in theory substitute it with the malicious script and override my genuine validator. So the question is:  
> **username_0**: how long could it take in average to a computer with 16 of today's CPUs, given a malicious script,  to find a nonce such that the hash and the address of the malicious script is the same hash and address of my genuine validator?  

---

## 1 answers

### Answer by username_3 on 2023-04-18. Score: 0

Actually, This is an interesting question. I would like to share my thought about this. I don't know if I made mistakes somewhere. Please just consider it as a reference.

**Problem:**

we want to consume all UTxOs locked at a validator address without knowing the validator script or without qualifying it.

**Approach:**

we could try to create our malicious script that **always returns to True**. However, Cardano will always check if the hash value of the actual script is the same as the hash value of the provided script when we submit the consuming transaction. So in our malicious script, we could add a random line such as nonce = 1, nonce = 2, nonce = 3 and so on until the hash value of our script is the same as the actual script.

**My calculation:**

As far as I know, the validator address is also the hash value of the script. I tried to take a sample validator address which is from plutus-pioneer-program (see [here](https://github.com/input-output-hk/plutus-pioneer-program/blob/044fa5d026a0d5f34ce6acb71d444e7d444fe125/code/Week02/assets/gift.addr)), it seems to be the shortest address type. *addr\_test1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla*. although I am not sure how the hash function is implemented, I can see all characters could be 0-9 or a-z and the length of the address *1wqag3rt979nep9g2wtdwu8mr4gz6m4kjdpp5zp705km8wys6t2kla* is 54. Based on this idea, I calculated the number of all possible cases of the hash value as the following

Total possible cases = (10 + 26)  54  cases

Where

* 10 is for 0-9
* 26 is for a-z
* 54 is the length of the address (is also the length of the hash value of the validator).

I am not really sure about the speed of today's CPU. let's say that 8 CPUs could handle 10^9 check (including compiling and running the malicious programs to take the hash value and check if it's expected) per second.

the result will be: (10+26)  54  / 109 / 3600 / 24 / 365 ~ **3.48 \* 10  67  years**.

It's a rough estimation, that's possible to have the case that some nonce value lead to the same hash value. for instance, nonce = 1 and nonce = 123978231231 return the same hash value, we need to check even more. Otherwise, in case we could find the result during the checking process soon, we don't need that long time.

Hope this is helpful!


---

