Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIP-0110? | Plutus v1 compatible script references #679

Merged
87 changes: 87 additions & 0 deletions CIP-0110/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
CIP: 110
Title: Plutus v1 Script References
Status: Proposed
Category: Plutus
Authors:
- Pi Lanningham <pi@sundaeswap.finance>
Implementors: []
Ryun1 marked this conversation as resolved.
Show resolved Hide resolved
Discussions:
- https://twitter.com/SmaugPool/status/1737454984147390905
- https://twitter.com/Quantumplation/status/1737704936089985339
- https://twitter.com/SmaugPool/status/1737814894710231161
- https://github.com/IntersectMBO/cardano-ledger/issues/3965
Created: 2023-12-20
License: CC-BY-4.0
---

## Abstract

Despite making up less than half the transactions on Cardano, Plutus v1 scripts make up 90% of the space dedicated to scripts (around 60% of the total block space). Increasing the space available to blocks is risky, as it impacts the block propagation time. This proposal puts forth a simple way to reduce this strain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My analysis showed that PlutusV1 scripts account for 41.3% and only 0.5% for PlutusV2 of the total size of blockchain since beginning of Alonzo, which means it is even lower that when taking Byron through Mary into consideration. So, 60% is definitely an overestimation. That being said 40% is still a lot.

Suggested change
Despite making up less than half the transactions on Cardano, Plutus v1 scripts make up 90% of the space dedicated to scripts (around 60% of the total block space). Increasing the space available to blocks is risky, as it impacts the block propagation time. This proposal puts forth a simple way to reduce this strain.
Despite making up less than half the transactions on Cardano, Plutus v1 scripts make up 90% of the space dedicated to scripts (around 40% of the total block space). Increasing the space available to blocks is risky, as it impacts the block propagation time. This proposal puts forth a simple way to reduce this strain.


## Motivation: why is this CIP necessary?

Plutus v2 introduced a way to publish scripts on-chain, and *reference* those scripts to satisfy the witness requirement. However, because this was done via a new field on the transaction (i.e. "Reference Inputs"), which shows up in the script context, this feature is not backwards compatible with Plutus v1.

However, despite consisting of less than half of the transactions being posted to the blockchain in late 2023, the bytes taken up by constantly re-publishing the same Plutus v1 scripts is nearly 60% of each block. Put another way, of the 151gb it takes to represent the 6 year history of the chain, roughly 60 gb of that (nearly 40%) can be attributed to the wasted space from repeating the same scripts in the last 2 years. This analysis was further confirmed by IOG in [this](https://github.com/IntersectMBO/cardano-ledger/issues/3965) issue.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"bytes taken up by constantly re-publishing the same Plutus v1 scripts is nearly 60% of each block"

I am probably misunderstanding this, but this does not make sense to me. How can PlutusV1 take up 60% of a block if in total it takes up 40% of the blockchain size since PlutusV1 was introduced?

Copy link
Contributor Author

@Quantumplation Quantumplation Feb 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 40% of the full chain (i.e. of the 151gb of on-disk storage for a fully sync'd node, at the time this was taken, 60gb of that was redundant scripts).

However, looking at an average over the last X time window (I think 1 month?), SMAUG found that:

  • considering only the space taken up by scripts, 90% of it was devoted to plutus v1 scripts
  • considering the whole block size, around 60% was devoted to the plutus scripts.

So it's exactly as you said: considering the full chain history, it's around 40%, because of the time before smart contracts were even a thing; but on average, on a continuing basis, you can expect around 60% of each block to be taken up by a plutus v1 script.

These are just rough motivating numbers, and it may be closer to 50% or 70%, depending on which time frame you measure in; The point was to express the severity of the problem, and that it's not going away, not to give a high precision measurement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, looking at an average over the last X time window (I think 1 month?), SMAUG found that

So, that is the statistics over 1 month. That should either not be present in this CIP or made it absolutely clear that it is just a statistic from an arbitrary period of in the past.

it's around 40%, because of the time before smart contracts were even a thing; but on average, on a continuing basis, you can expect around 60% of each block to be taken up by a plutus v1 script.

First of all it is 41.3% since smart contracts where a thing. See my analysis.

Second of all, this math makes no sense. "40% of blockchain consists of PlutusV1 scripts" literally means on average every block will be 40% PlutusV1 scripts. You can't cherry pick a small period with higher usage and use it as an average.

So, could you please remove that 60% statistic from the CIP, since it is not only confusing but also does not serve as a good representative of the overall usage pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what are we trying to achieve here?

Your analysis mentioned that 60gb of overhead was due to redundant plutus v1 scripts; The current on-disk storage for all eras was 151gb (I don't have an updated view). 60gb is 39.7% of 151gb, or about 40%.

It feels like you're picking a fight over me using the phrase "about 40%", instead of an exact 41.3%? What does the extra significant digits there help achieve? Does it materially change the point, or the motivation for adopting the CIP?

As for the 60%, my wording clearly says end of 2023; I'm happy to make it clearer, but I think a statistic that talks about the existing, ongoing usage of the chain, which normalizes for recent trends, is an important view of the picture. The point being that the problem isn't going away: for example, it would be one thing if the first 3 months of Alonzo produced 59gb, and then in all the time since, we've produced an additional gigabyte.

I'm not cherry-picking a small period, I just picked a recent period, and the implication that I'm being deceptive or dishonest is insulting, when your own analysis supports the same conclusion: that this is a problem, and needs to be addressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworked the explanations to hopefully make it clearer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like you're picking a fight over me using the phrase "about 40%", instead of an exact 41.3%?

No, not at all. ~40% is fine. Also I am not trying to pick a fight. I am trying to make sure we have an accurate picture here.

As for the 60%, my wording clearly says end of 2023

It is like saying: "Last December the average temperature was -10C, so we can conclude that for the next few years that should be the average temperature every month."
So, what I am saying is the 60% average is wrong. There are no numbers backing up this "average" usage statistic, while there are clear numbers showing that the number is approximately 40%. I hope it is more clear now what I am trying to say.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implication that I'm being deceptive or dishonest is insulting

Also, I am not implying that you are being deceptive. There is no need to get defensive, because no one is trying to attack you here. We are all on the same team. All I am trying to do is point out a flaw in the CIP.

So, just to make it really clear, I am trying to say that using a small sample to infer a bigger picture is wrong, especially when there is a clear and accurate analysis available. That's all.


This problem isn't going away: while protocols may migrate to new Plutus v2 or v3 scripts, these old protocols will exist forever. Liquidity locked in these scripts, sometimes permanently, will mean that there is always an arbitrage opportunity that incentivizes a large portion of the block to be occupied by continually republishing these v1 scripts.

> Historical Note: At the time that the babbage hardfork happened, the belief was that Plutus v2 would be attractive enough to encourage migration of that traffic. In practice, this simply isn't true, and circumstances like locked liquidity were unforseen.

Additionally, raising the block size is considered incredibly sensitive, as it impacts block propagation times.

A simple, backwards compatible mechanism for plutus v1 protocols to satisfy the script witness requirement, without changing the script context and causing breaking changes for Plutus v1 scripts, would alleviate quite literally millions of dollars worth of storage requirements, user pain, and developer frustration.

## Specification

We propose relaxing the ledger rule that fails Plutus v1 scripts in transactions that have reference inputs, and to construct a script context that excludes reference inputs.

The ledger rule shouldn't change in other ways: for example, Plutus v1 scripts should still fail in the presence of inline datums or reference scripts on spent transaction inputs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to fail on reference scripts in regular spending inputs?
Whenever a regular input includes a reference script it constitutes a usable reference script in that transaction, so it feels strange and inconsistent to disable just that functionality. Especially considering that the user will have to pay extra for spending that output starting with Conway, since it contains a reference script.

I would suggest we just translate the TxOut while omitting translation of the reference script. In other words it would look like a regular TxOut to PlutusV1 script.

I do agree about the inline datums, we should still fail translation on their presence in the inputs.

@michaelpj, @zliu41 and @Quantumplation any objections to allowing reference scripts in spending inputs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with any relaxing of these rules; This part was written when I was unsure whether even the most gentle version of this was going to be accepted.

When I've raised this in the past, the response I got was that any hiding of information about the transaction when constructing the script context was considered dangerous and wouldn't be supported.

Hence, my original proposal was about including reference scripts in the witness set, which isn't directly visible to the script context.

It was quite a pleasant surprise when MPJ suggested that we just allow reference inputs like normal and leave them off the script context.

So, I have no objection to further relaxations if the ledger team themselves are ok with it, just understand that I was writing this from a posture of "what has the best chance of getting the ledger teams approval, and thus makes the minimal amount of semantic changes to plutus v1" 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's worth noting that I'm also fine with not relaxing this, as I can't think of any scenario where this buys us dApp developers any benefit. i.e. it's largely immaterial to me. Whereas the ability to satisfy a script witness via a reference input is hugely beneficial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what has the best chance of getting the ledger teams approval

😄

You got our full approval on this CIP.

I personally would prefer to have consistency. So, if we are enabling reference scripts for PlutusV1, then they should work in the same way as they do for PlutusV2 and PlutusV3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I appreciate the effort by @Quantumplation to make the minimal relaxation possible to allow the key usecase. Generally I do think that's the way to go.

However, I agree with @lehins that if we're going to allow reference scripts to be used in V1 we might as well put in the "whole feature". It's not much worse and otherwise it's a weird corner case.


## Rationale: how does this CIP achieve its goals?

The main concern with this relates to backwards compatibility. The ledger makes very strong commitments regarding the behavior of scripts: any observable change represents a risk that there is some script out there that will either be unspendable when it should be, or spendable when it should not be.

Because of this, any such change which violates this must satisfy a burden of proof with regards to both the benefits and the risks. This was in fact considered [in the original CIP](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0031#how-should-we-present-the-information-to-scripts), and at the time, it was decided that the justification would likely not meet that high bar.

Thus, as a rationale for this CIP, we repeat that analysis, hopefully with a different conclusion.

In terms of benefit, this approach would immediately allow all major plutus v1 dApps to reduce their transaction sizes dramatically. Some napkin math for both Sundae and Minswap shows that this would cut around 85% of the transaction size for each transaction; Considering the portion of block space currently taken up by Plutus v1 scripts, this represents a significant savings.

It is hard to overstate the long-term positive impact that this change could have for real users of the Cardano blockchain.

In terms of the risks, there are four main risks to consider:

- Funds that should be spendable are suddenly not spendable;

In this case, a user could simply continue to use the existing witness mechanism to provide the scripts, and those funds become spendable again.

- Funds that should not be spendable are suddenly spendable;

In this case, it is very hard to imagine a scenario where this would be true that isn't crafted intentionally. It would have to be some script that was dependent on the transaction fee being above a certain threshold, which is already a dangerous assumption to make given the updatable protocol parameters. In other instances (such as the change to how the minimum UTXO output is calculated) this kind of risk hasn't been an obstacle.

- The execution units change, without changing the outcome, resulting in a different cost for the user;

In this case, the cost would only go down, and it is again hard to imagine a scenario where this is at material risk of violating some protocols integrity in a way that is not already compromised.

Given the parallel plans to include reference scripts in the cost of the transaction, outlined [here](https://github.com/IntersectMBO/cardano-ledger/issues/3952), further mitigates these concerns.

## Path to Active

### Acceptance Criteria

- [ ] Review of this proposal by the relevant subject matter experts
- [ ] Implement the change in the cardano-ledger and cardano-node repositories
- [ ] Include this change in a relevant hard fork

### Implementation Plan

- [ ] Update the formal Agda specification
- [ ] Implement [minFeeRefScriptCoinsPerByte] or similar approach, as described [here](https://github.com/IntersectMBO/cardano-ledger/issues/3952)
- [ ] Update the implementation [here](https://github.com/IntersectMBO/cardano-ledger/blob/fdc366df654fc02b1668012342732d41eaa099fe/eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs#L94-L97)
- [ ] Update property based tests to cover these scenarios

## Copyright

This CIP is licensed under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/legalcode).