IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.56k stars 477 forks source link

How is costing determined? #4375

Open kozross opened 2 years ago

kozross commented 2 years ago

Describe the feature you'd like

This relates to #4233, specifically this comment here. Clearly the mempty costing is a default, and probably not accurate for the SECP256k1 builtin required by the issue. However, I'm not sure how costing is determined, or what needs to be done to determine it. Is this documented anywhere? If yes, it'd be good to have it more visible; if not, what is the process of costing?

Describe alternatives you've considered

Currently, you can define all costs as mempty, but this is clearly not accurate, as operations can have very different costs.

michaelpj commented 2 years ago

I think for the time being we're assuming that the Plutus team will handle determining costing functions. In the future we'd like to encourage contributors to do it, but it's a bit tricky. If you're willing and have time to contribute to this you could probably help by extending the benchmarks here to include the new builtin.

Ultimately it's empirical: make some benchmarks, run the function in question with arguments of varying sizes and see what costing function fits. You can omit parts of the domain that cause errors (relevant for signature verification as that means we only care about appropriately-shaped inputs).

cc @kwxm

kwxm commented 2 years ago

When the SECP256k1 PR is merged I can work out what the cost model should be. A problem is that to come up with coefficients for costing functions we have to run some benchmarks on a reference machine that's reserved for that purpose, so it's not easy for external contributors to generate the required data. Costing functions also have to be carefully audited before deployment to make sure that the claimed cost of a builtin is accurate in order to avoid scripts which run for much longer than the cost model would have you believe.

We will produce a document about this in due course, but other things are currently taking priority.

effectfully commented 1 year ago

We will produce a document about this in due course, but other things are currently taking priority.

@kwxm is there such a document now? Is it accurate regarding what needs to be done in order to determine costing? Is it complete?

kwxm commented 1 year ago

We will produce a document about this in due course, but other things are currently taking priority.

@kwxm is there such a document now? Is it accurate regarding what needs to be done in order to determine costing? Is it complete?

Unfortunately not. We have an internal document that's rather outdated and needs to be updated and tidied up for general consumption. That's another thing that's in the backlog. There's a placeholder in the Plutus Core specification, and it might be worth putting a high-level description of the costing process in there as a stopgap so that people can get some idea of how things work.

effectfully commented 1 year ago

OK, it sounds like this is not being considered high priority at the moment. I'm therefore adding the respective label.