13

So I am currently on lecture 1 on the Plutus Pioneer Program. In the lecture they said the redeemer is the input information that the script uses to decide if a specific UTxO can be spent. I watched a video that was made two years ago that said the redeemer is used to decide if a wallet can receive Ada from a smart contract. The person in that video did say that these things might change because things are still under development. Can someone clear this up for me? What exactly is a redeemer as of right now? What is a redeemer's role in sending transaction and in smart contracts?

12

From https://iohk.io/en/blog/posts/2021/04/13/plutus-what-you-need-to-know/:

When validating an address, the script will access the data being carried by the output, the transaction being validated, and some additional pieces of data called redeemers, which the transaction provides for every input. By looking up all this information, the script has enough context to give a ‘yes’ or ‘no’ answer in what can be highly complex situations and use cases.

In lecture 1 of the current plutus pioneers program, you find a redeemer on the auction validation script. When making a bid, there are essentially five cases to check. All these five cases need to pass or the transaction will not be even committed to the blockchain (which is good, because you're saving on fees for something that won't succeed anyway):

  1. Is the bid sufficient (the bid is >= the minimum valid bid)
  2. The auction hasn't closed

The three other cases also do data checks (output datum/value, bid refund).

The redeemer (in the auction example) itself is a simple data type that we can define (AuctionAction) to do data validation (particularly on inputs).

2
  • That was a great explanation.Thanks.
    – szhang9921
    May 16 at 0:22
  • Thank you. If you're happy with the explanation, make sure to mark the answer as a solution to your question as it helps other StackExchange users to see what questions have/haven't been answered sufficiently.
    – Matthias Sieber
    May 16 at 3:53
7

In simple terms, redeemer is the data that the user of the smart contract provides to the smart contract.

In the simple UTxO model, redeemer is your signature. By providing your signature, you prove that you own the UTxO and in return you are allowed to spend that UTxO.

EUTxO takes this one step further. How are you going to spend an EUTxO? You have to provide all the data that EUTxO needs and depending on the data you provide, you are allowed to spend it or not.

3

Before (E)UTxO - There Was UTxO

Understanding how a UTxO model works (such as BTC) may help you understand the implementation of (E)UTxO in Cardano.

The UTxO Model

A UTxO model, meaning: unspent transaction outputs from previous transactions1 will typically implement a validator and a redeemer for any given new transaction (at least, this is the case in BTC).

Validators and Redeemers

The validators job is to return a boolean value as to whether the UTxO can be spent or not. In BTC the validator is implemented in BitCoin Script and is about as simple as it could be. It does, however, take a redeemer (which in the case of BTC is a representation of transactional digital signatures); and the validator uses the redeemer to either allow the UTxO to be spent or not.

Cardano | The (E)UTxO Model

Within Cardano we use scripts to evaluate whether or not a given (E)UTxO may or may not be spent. An address in Cardano points to a script - the script contains arbitrary logic and takes a redeemer as its input/parameter(s) - which are now also more general in nature, as they need to satisfy the constraints provided by the arbitrary logic within the script.

By triggering the script (attempting to create a new transaction), the redeemer will be passed to the script, the script will be executed and will determine whether or not the (E)UTxO can be spent or not.

Summary

A redeemer is used as input to an (E)UTxO script in order to determine whether or not the extended unspent transaction output may or may not be consumed, given the arbitrary logic provided within the script.

FYI: Cardano addresses point to scripts, the script may be simple or extremely complex.

I found this video by Michael Peyton Jones to be pretty informative and perhaps a little more intuitive than the first lecture presented within the Plutus Pioneer Program:

https://youtu.be/usMPt8KpBeI

However, it may be a little outdated? I'm still working my way through the second cohort.


Footnotes:

  1. Think of an unspent transaction as the change you're given in a shop when you hand a $20 bill for a $5 item, the $15 change is YOUR UTxO and is secured using public-private key cryptography.
1

There is an interesting example in one of the Pioneer lectures which implements Uniswap on Cardano.

A redeemer is not only used to justify that a UTxO can be spent, but also the manner in which it will be spent. The validation script will then place the necessary constraints on the creation of the transaciton based on who is trying to spend it and how they are trying to spend it.

In the screenshot attached from lecture 10 of the first iteration of the Plutus Pioneer Program, the blue lines represent the redeemer as an input to the UTxO's validation script (represented by the blue and red circles) which, in this case, is validating the consumption of a UTxO which represents a liquidity pool.

You can see four different labels on four of the blue lines - Create, Swap, Add and Remove. These represent different constructors for the redeemer data type being used and tell the script what action the user is trying to take.

For further details of exactly what each redeemer does, you can read more and find a link to the video here.

Uniswap on Cardano Example

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .