Gift validator smart contract : Iteartion #2 lecture #2 : Lars Brünjes (pioneer program)

In his 2nd lecture of the 3rd iteration Lars Brünjes present a simple on-chain smart contract that validates anything. He calls it the gift.
As I understand the address of this script would be its hash and anything sent at this address could be reclaimed by anybody knowing it’s address because the validator script validates any thing.

What Is not too clear is what happen to the script address once it is used in a transaction ?
is it destroyed, unusable or in that case, if the transaction’s output the script hash again, it can be used a second time ? If that so the term unspent transaction does not hold anymore.

Just like “normal” addresses, script addresses can be used again and again.
Just like on payment key addresses, there have to be unspent transaction outputs (UTxOs) on the script address, in order to use them as inputs to a transaction that spends them.

The only difference are the conditions, when such a transaction is allowed.
For payment key addresses, the simple rule is: the transaction has to be signed by the private key of the payment key.
For Plutus script addresses, the rule is: the validator script has to return true (and can check very complicated conditions on the way, but is restricted by the data given to it in (reference) inputs).
In between that are the native scripts which are more famous for being used as minting policies, but can also be used for script addresses. They can then state things like: “UTxOs on this address may only be spent after slot X and if signed by these two keys or any of these three keys.”

To reuse these, they don’t have to be “given back” by transactions using them. A lot of transactions can use them in parallel (if there are enough UTxOs on the address). They can be completely enptied and then used again months or years later.

It is just these conditions – a simple payment key, a native script with some conditions, a Plutus script making quite complex computations to decide yes or no – that are hashed and encoded in the address. Forever.

1 Like

That’s was not clear to me. I had this idea from the Bitcoin world, and false, that addresses were consumed by transactions and therefore could not be used twice. In fact it’s not recommended in bitcoin but feasible.

That part is still not clear. you seem to make a difference between UTxO and the address. For me the UTxO is an addresse that was not used.

When you say “UTxOs on this address” that’s really strange to me. how can there be several UTxOs at one address ?

No, try to forget that.

A lot of wallets in Cardano are now single address wallets. They use the same address for all transactions. And it makes sense to split up the funds, so that you can do multiple transaction using different UTxOs in parallel.

On my main wallet, I have dozens of UTxOs on its single address.

There are basically two reasons that is “discouraged” in Bitcoin:
Privacy – that is not really relevant for usual Cardano wallets, since all addresses contain the same stake key hash anyway and can easily be identified as belonging together.
Security – there is the argument that if only the hash of the public key is known, until that address is used for the first and only time, that is more secure in the (rather far-fetched) case that a vulnerability for known public key or known previous signatures is found

Anyway, conceptually a UTxO and an address are two totally different things also in Bitcoin.
A transaction sends in its outputs to addresses (that may have been used before). And those outputs are unspent until they are spent, used in further transactions.

The addresses of smart contracts have to be used hundreds and thousands of times in usual cases for the contract to make sense. All orders to a DEX usually go to the same address and are then matched by market makers, for example.

1 Like

Ok,
So to summarise and see if I understand correctly.
An address can have an UTxO or not attached to it.

  • If it has then, it can be used as an input in a Tx.
  • If it does not then there are two cases:
    1. it was used at least once as an output of a transaction but its UTxOs were all consumed in one or several Tx
    2. it never had anything sent to it. It’s unknown in the blockchain.

In the case of several UTxOs rejoining at one address, let’s say two UTxOs sit at one address, does the EUTxO permits using only of those ? If I understand correctly this should be feasible and I guess the consuming Tx will have to recreate an output with the remaining UTxO at sitting at the same address. But in that case, I’m not sure if we should speak of the same old UTxO or of a new one created at the Transaction. What identify a UTx0 beside it’s sitting address and datum attached with it (or is it with the address)?

Transactions actually do not identify the inputs they consume by address, but by transaction and index of the output of the transaction.

They say: “Take ths Ith output of transaction X and the Jth output of transaction Y.”

They do not have to consume all outputs on an address, but they can take several if one doesn’t have enough. They can take inputs from several different addresses.

The address just determines what conditions must be fulfilled, what keys have to sign the transaction, what scripts have to be executed successfully.

And in general, transactions do not have to put something back on the same address.

If it is a single address wallet, they usually will put back “change” (all inputs have to spent completely, but they rarely match what should be sent away exactly, so the rest has to go back to your own wallet), but if it is a multi address wallet that change will go to a new unused address.

And contracts may require that an output goes back to the same address. But that then is a speciality of the contract and not a general requirement for all transactions.

1 Like

The distinction is getting clearer. Thank you @HeptaSean

Ok… Is it correct to say also that :

  • one signature can be enough to spend UTxOs from several addresses,
  • but that some addresses may require several signatures to spend their uniq UTxO ?

Finaly, correct me if I’m wrong please. if someone wants an output to be spend by 2 different signatures separately, signature A OR signature B, then he cannot send the transaction’s output to 2 differents addresses. He needs to create a script address that will validate the OR condition.

In special cases, yes: if it is the same payment key hash combined with different stake key hashes (or with none). For the usual addresses of a wallet, different address means different payment key hash, means different signature required.

Yes, but that would require at least a simple/native script. A Plutus script can, of course, also require that.

Yep, but for such simple conditions, the native scripts that were already available prior to Plutus are enough.

1 Like