0

I have been looking into creating a blackjack game on the Cardano Blockchain. I started with learning Haskell, and writing a simple blackjack CLI game. It was heaps of fun and a bit of a learning curve since I have never used functional languages before!

Unfortunately I misunderstood one critical thing about Plutus apps which mean that I could never implement this game in a truely decentralized way. That misunderstanding is that I could run arbitrary code and transform the datum in the on-chain code. This is true on Ethereum but not in Cardano, where the on-chain code can only determine if a transaction is valid.

I can't see any technical reason why a datum transformation couldn't be performed on a single UTXO, apart from performance considerations. So my main questions are:

  1. Is there any technical limitation preventing Cardano from implementing this functionality on L1 in the future? Or is it just to prevent L1 from becoming bloated with excessive datum storage and code execution?

  2. Will there be a layer 2 that allows this functionality? Is this the idea of IELE?

Appreciate any clarification here!

3
  • I should clarify that I need to draw a random card and update the state on-chain for this to be a truely decentralized app. It's true that I could probably setup some oracle off-chain to draw a card and update the game datum but this would be a lot more complex and a lot less decentralized.
    – micwallace
    Dec 28, 2021 at 3:35
  • Even if you had the functionality to change the datum on-chain, you would not be able to draw a random card. On-chain code is deterministic. Randomness can never be achieved, therefore. This is also true in Ethereum where you couldn‘t implement this as well. You can ask yourself, how would any node be able to verify that the card was really drawn randomly by another node of the network ? It is simply impossible: randomness cannot be proven and is therefore not implementable on-chain.
    – Jey
    Dec 28, 2021 at 8:27
  • @Jey At least not until we have verifiable random oracles on chain
    – zhekson
    Jan 27 at 21:45

1 Answer 1

0

Having a validator script with the ability to change the datum would not increase the power of Cardano's smart contract model. The reason is that, in the current model, validators can only use (as inputs to their logic) data that the transaction provides. The validator cannot run anything that the submitter of the transaction cannot also run. It makes, therefore, no difference if the datum is computed on- or off-chain.

The real reason you have the impression that the Ethereum model is more powerful is that, on the Ethereum blockchain, a smart contract can use the whole blockchain at execution time as input for its computation. This also means that the submitter of the transaction cannot know for sure the result of the smart contract execution as the blockchain could have changed between the moments of submitting and executing the transaction.

The biggest difference I see between Ethereum's and Cardano's smart contract models is that on Cardano it is more difficult to implement some uniqueness constraints in a decentralised way. For example, a minting policy cannot make sure that a token name is unique if the token name space is too large to fit into a script datum. A trusted party is necessary to enforce this uniqueness.

Apart from this, a random number generator is impossible on-chain and no existing blockchain implements one. Randomness always needs to be pushed to the chain from the outside world. This can be done by the means of oracles or by signed random numbers of a trusted off-chain source.

16
  • I'm not sure if you understand the question. I completely understand what UTXO is and no way calling Ethereum superior! But Cardano validators as they stand can only classify a transaction as valid or not. They still have access to the datum of the input UTXO/s to determine validity, but they cannot run code to set the outputs or datum of transactions that try to consume that UTXO. I don't see how not having access to the global blockchain state would be an issue here, hence my question.
    – micwallace
    Dec 29, 2021 at 11:49
  • Also there are a few ways of getting random numbers on-chain, it's not impossible.
    – micwallace
    Dec 29, 2021 at 11:54
  • I understood your question. Maybe you did not understand my reply. Also, I did not imply that you think Ethereum is superior. “Powerful” is meant in the programming sense.
    – Jey
    Dec 29, 2021 at 13:10
  • Maybe it is not clear to you that the validator script really has access to nothing except the inputs; not even to the slot number. It is purely functional.
    – Jey
    Dec 29, 2021 at 13:17
  • 1
    No, by inputs I meant the whole transaction. This transaction already includes the updated datums. So in a way, the model does already what you are describing. There is no need to have the validator return anything else than a boolean.
    – Jey
    Dec 31, 2021 at 7:46

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.