user3362334
user3362334

Reputation: 2180

Prove that you executed view function in Solidity

I am looking into possibility of using Smart Contracts in our Casino. Because we don't want to have the players pay the fee for every hand they play, we want to use "view" transactions that don't modify the state and thus don't require any gas. This, however, introduces the following problem: "Since the transaction isn't saved on the blockchain, it is hard (or impossible?) to prove to someone that you really called the smart contract function (and that you called it only once).

One option that I thought about was to have the client(browser) call the function on smart contract. However, since our backend also needs to "know" the result, the player can, of course, change the result on his end, and send the wrong result.

If, on the other hand, we have our backend call the function on smart contract, there should be a way to prove to the player that we really called the smart contract and that we called it just once. I find it hard to do that.

One idea was to call the smart contract from client, encrypt the data using public key and send it to the backend so it can decrypt them and see the result. However, the player wouldn't know if the server really used this data, and I'm not even sure if encrypting with public key has any sense, since the execution of the smart contract function is public, so I guess everyone would know the input.

So, my question is, is there a way to convince the player that we really called the smart contract and that we called it just once?

EDIT: One other idea that came to my mind is to use one private/public key pair per game session, so that in the end of the session the player finds out the private key and if we store the history of all bet results on the client, the player can check if those were real results using the private key he got.

There is still a question if a player would see the bet result before it got encrypted on the smart contract

Upvotes: 0

Views: 1149

Answers (2)

Nulik
Nulik

Reputation: 7380

  1. Before you implement Casino on the blockchain check transaction costs. Sometimes fees can be 30 dollars per transaction, will your use be playing games with these costs? Currently these transaction costs can only be paid by trading robots that do currency arbitrage.
  2. Calling a contract function is FREE. You can read any data from the contract without issuing a transaction. No gas is needed. This only works for functions that do not modify the State. You can feed the data to the blockchain yourself and users can read it at no cost.
  3. It is not doable what you want to do without storage, you need somehow to flag that the READ operation occured at least once, and for that you need to issue a WRITE operation (which has a cost).
  4. Data is not encrypted using public keys. Data is encrypted using private keys and public keys are used to determine the identity of the signer. But you are talking about symmetric encryption here, where both entities have to hold the secret key used to encrypt the data.
  5. To store anything on the blockchain you need to send a transaction. Imagine that Ethereum is an SSD disk, and everytime you want to store a file, you need to send a transaction, signed by your private key. This is how it works. Reading is free, but to store something, impossible without a transaction. Can you create an App with read-only hard disk? No!
  6. Are you sure you need Ethereum? If all you need is to store some data maybe some kind of blockchain that is friendly with just storing plain data would work.
  7. Probably, you can store user's session in 0x Mesh network as a Maker Order of something. It is not meant for that, but it is Peer to Peer network, it is quiet big, and sending the Order is free, but canceling the order requires a payment. So, this scheme might be useful for you. The user's session will expire the same way as the 0x Mesh order is expiring. At no cost. All orders are signed, so it is kind of suitable for what you need. But it is not meant for games.

Upvotes: 0

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83566

Is there a way to convince the player that we really called the smart contract and that we called it just once?

The player can sign a message in their wallet and then your server calls the smart contract with this message. The smart contract decrypts the message and acts based on it. The transaction is pushed to the network by your server and the server has a hot wallet that covers ETH cost.

Alternatively, you can use a layer 2 network like Optimism where transaction costs are cheaper. You can also use Gas Station Network with relayers to make the user pay in a token instead of Ether.

Upvotes: 0

Related Questions