IntersectMBO/plutus

documentation for costing changes in plutus v3

michele-nuzzi opened this issue · 9 comments

Describe the feature you'd like

recently I was testing some plutus v3 contracts.

at submission I noticed that lates costs in sancho are an array of length 251 instead of 233 expected

it does not appears that new builtins where added, instead it seems that some have changed their formula

I have notice quotientInteger and remainderInteger now quadratic in both argument

I also noticed that 2 parameters are negative, can you confirm is not a bug?

it would be nice to have clear how to use the new costs introduced and which builtins have been changed

Describe alternatives you've considered

No response

additionally, is there anywhere I can join to get notified about these changes as they happen (some discord server or similar)?

if the negative integer is not a bug I assume it is encoded as negative integer on the respective language view for the script data hash calculation in the various transactions

@kwxm please respond to these once you have some time.

Thank you very much

If an explicit mapping from the position of the cost in the array to the cost property name is also available that would be of great help

kwxm commented

@michele-nuzzi Apologies for the delay in getting back to you.

recently I was testing some plutus v3 contracts.

at submission I noticed that lates costs in sancho are an array of length 251 instead of 233 expected

it does not appears that new builtins where added, instead it seems that some have changed their formula

I have notice quotientInteger and remainderInteger now quadratic in both argument

I also noticed that 2 parameters are negative, can you confirm is not a bug?

That's correct. We've updated the cost model for PlutusV3 to account for improvements to the evaluator and the addition of some new built-in functions and we've also improved the precision of costing for some functions, including the integer division ones. These changes should reduce the CPU costs of a typical script by 20-30%; memory costs will be essentially unchanged. The negative numbers are correct, and we enforce a minimum value to make sure that the cost of calling the function is never negative. You can see the code that does the calculation here.

We're aware that there's not much public documentation about the cost model, so I've attached a draft of an explanation: this may still contain some typos, so read it with caution. I hope it'll still be of some help though.

cost-model-overview.pdf

kwxm commented

additionally, is there anywhere I can join to get notified about these changes as they happen (some discord server or similar)?

Yes. Intersect has a Discord server where you could talk to us a bit more directly, in the plutus-working-group channel. I think that you may have to be a member of Intersect to be able to access that though, and there's a small fee to join ($10 I think).

kwxm commented

If an explicit mapping from the position of the cost in the array to the cost property name is also available that would be of great help.

That's determined by the ordering of the parameters here. A bit of translation is required, but it should be fairly clear what's going on.

Thank you @kwxm, the ordering helped a lot, if this issue is not useful to you guys I think we can close it.

Great then! Glad we were able to help. Thank you @kwxm!