0

I have a JS function that generates a random number that is inserted into the web3js function as a parameter. I have the following questions:

1) Is it possible for people to decode that input parameter and see the number?

2) Is it possible to interfere with the JS script and inject a false number (though it will be failed, cause it verifies the number with the one stored on Ethereum).

3) What would be the safest way to generate a random number in the frontend and pass it to Ethereum?

  • 1) Yes, 2) Yes, 3) Safe from what? – user19510 Apr 7 '18 at 4:06
  • Thanks for the answer. I don't want people to see the number X' stored on Ethereum, in a struct, so whenever the randomly generated X from the frontend matches the X' stored on the blockchain, an event fires. How could people abuse this? – Ruham Apr 7 '18 at 5:31
1

The data stored in the network can be seen by others.

I understand that your idea is to store a number and when the contract is presented with a number that matches, some code is executed.

Because the data is visible, anyone will be able to send that number to trigger the execution of the code. However, you could first, take the hash of the number and then store the hash instead. When you send the random numbers, the contract computes the hash of the presented number and compare it with the stored hash. In this way, people will not know what is the number stored but it will be clear when the stored and the presented number are the same.

About JS, you just need to be sure that your front end is not compromised.

  • Thanks for the answer. Do you mean hashing the number in frontend, and send the hashed value as the function input? – Ruham Apr 8 '18 at 0:42
  • 1
    Yes. The number that you want to save should be hashed on the front end before storing it. However, the second number that is sent to check if is the same as the stored one is sent without hash and the function in solidity should get the hash and compare it to the stored hash – Jaime Apr 8 '18 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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