简体   繁体   English

证明你在 Solidity 中执行了视图 function

[英]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 .因为我们不想让玩家为他们玩的每一手牌支付费用,我们希望使用不修改 state 的“查看”交易,因此不需要任何 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).然而,这引入了以下问题:“由于交易没有保存在区块链上,很难(或不可能?)向某人证明你确实调用了智能合约 function(而且你只调用了一次) .

One option that I thought about was to have the c lient(browser) call the function on smart contract.我想到的一个选择是让 c lient(浏览器)在智能合约上调用 function。 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.另一方面,如果我们在智能合约上调用 function 的后端,则应该有一种方法可以向玩家证明我们确实调用了智能合约并且只调用了一次。 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.但是,玩家不知道服务器是否真的使用了这些数据,我什至不确定用公钥加密是否有任何意义,因为智能合约 function 的执行是公开的,所以我想每个人都会知道输入。

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.编辑:我想到的另一个想法是每场比赛使用一对私钥/公钥 session,以便在 session 结束时,玩家找出私钥,如果我们将所有投注结果的历史存储在客户端,玩家可以使用他得到的私钥检查这些是否是真实的结果。

There is still a question if a player would see the bet result before it got encrypted on the smart contract仍然存在一个问题,玩家是否会在智能合约上加密之前看到下注结果

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.交易由您的服务器推送到网络,服务器有一个热钱包,可以支付 ETH 费用。

Alternatively, you can use a layer 2 network like Optimism where transaction costs are cheaper.或者,您可以使用交易成本更便宜的Optimism 之类的第 2 层网络。 You can also use Gas Station Network with relayers to make the user pay in a token instead of Ether.您还可以将加油站网络与中继器一起使用,让用户使用代币而不是以太币进行支付。

  1. Before you implement Casino on the blockchain check transaction costs.在您在区块链上实施 Casino 之前,请检查交易成本。 Sometimes fees can be 30 dollars per transaction, will your use be playing games with these costs?有时费用可能是每笔交易 30 美元,您会用这些费用玩游戏吗? Currently these transaction costs can only be paid by trading robots that do currency arbitrage.目前,这些交易成本只能由进行货币套利的交易机器人支付。
  2. Calling a contract function is FREE.调用合约 function 是免费的。 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.这仅适用于不修改 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).如果没有存储,您想做的事情是不可行的,您需要以某种方式标记 READ 操作至少发生一次,为此您需要发出 WRITE 操作(这是有代价的)。
  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.想象一下以太坊是一个 SSD 磁盘,每次你想要存储一个文件,你都需要发送一个交易,由你的私钥签名。 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.可能,您可以将用户的 session 存储在 0x Mesh 网络中,作为某物的制造商订单。 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.用户的 session 的到期方式与 0x Mesh 订单到期的方式相同。 At no cost.免费。 All orders are signed, so it is kind of suitable for what you need.所有订单均已签名,因此适合您的需求。 But it is not meant for games.但它不适用于游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM