1

We're working with the project in which we're storing some confidential details (different for each user)in smart contract, we don't want to show this information to anyone else even miner, thus we are planing to use pure function. As pure function will not change the state of the Blockchain and miner won't execute pure function's transaction.

But that all are our assumption, we would like to understand how pure function works!

For instance, consider following smart contract.

contract Sample {

    function mul(uint _a, uint _b) external pure returns(uint) {
        return (_a * _b);
    }
}

1) Where the pure function get executed?

2) Anything which change the state of the blockchain is verified by miners. Will miner perform any role in this type of execution?

3) If miner will execute it, will they able to see the value of a and b?

Edit:

We're working on some requirement, where each user can claim the reward, but we don't want to make it visible(reward amount) to other users, only admin and particular user who got reward only should be knowing the same.

  • 1
    If you store data on smart contract then everyone can see it medium.com/aigang-network/… – Ha ĐANG Aug 21 '18 at 6:59
  • @HaĐANG, we're planing to encrypt it and save it to SC – Div Aug 21 '18 at 7:01
  • Could you elaborate a bit more on what you are trying to achieve by using a pure function? – Henk Aug 21 '18 at 7:18
  • @Henk, Question updated. – Div Aug 21 '18 at 7:28
  • 1
    The pure modifier is not going to help you with this. A big part of the problem is that, when someone claims a reward, it's going to be transfered and everyone can see the amount of the transfer. The transfer must either happen inside a transaction, or off-chain. – Henk Aug 21 '18 at 7:39
1

we don't want to show this information to anyone else even miner, thus we are planing to use pure function.

Maybe you should read the docs on pure functions. I have a feeling they are not what you think they are.

A pure function is a function of which the output is entirely dependent on the input parameters. They can never read from, nor store data to the blockchain. This makes them sutable as utility functions. Don't be fooled; they can still be run as part of a transaction execution.

All data that's put on the blockchain is visible to everyone. To keep something private, encrypt the data first and never send the key to the blockchain.

The pure modifier does not make your data secret.

To answer your questions:

Whether the function actually gets mined, and therefore run by every node in the network, depends on your situation. If you're making a call to just the pure function from web3, then no, it won't be part of a transaction. It will only be run by the node you are directly connected to. If you're making a call to the pure function from another smart contract inside a transaction, then yes, the execution will be done by the whole network and therefore, the input parameters will be visible.

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.