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-0109? | Modular Exponentiation Built-in for Plutus Core #641

Merged
merged 17 commits into from
Feb 8, 2024

Conversation

perturbing
Copy link
Contributor

@perturbing perturbing commented Dec 18, 2023

Hi

This CIP proposes an extension of the current plutus functions to provide support for the efficient calculation of modular exponentiation with inverses.


Rendered proposal on branch.

@perturbing perturbing changed the title add readme for modular exponentiation CIP CIP-???? | Modular Exponentiation Built-in for Plutus Core Dec 18, 2023
@rphair rphair added the Category: Plutus Proposals belonging to the 'Plutus' category. label Dec 19, 2023
@MicroProofs
Copy link

I would say the use cases are both simplifying the usage of the new BLS builtins. Currently you have to pass in the inverses of scalars because calculating them is prohibitively expensive (close to 10% cpu). In the case of a Plonk implementation made by perturbing.

This also allows for signature and pub key aggregation on-chain to be used for other signature schemes like schnorr and ecdsa256k. Currently adding points on those curves is prohibitively expensive since the calculation of adding points requires an inverse calculation.

Copy link
Collaborator

@rphair rphair left a comment

Choose a reason for hiding this comment

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

@perturbing thanks for your submission but this isn't fully ready for review unless you add a Path to Active that addresses the items here, and maybe also update the other sections with these particulars:

\end{equation}
$$

We propose to also include this extension to the plutus built-in, for optimized inversion when this is possible. This is inversion is not guaranteed to exist for all numbers $b$, only when the modulus $m$ is a prime number this is guaranteed. We also propose that the built-in fails if this inverse does not exist, and if a modulus is provided that is smaller than one.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm slightly unsure about this. If we don't have this we're just requiring the user to do the inverse themselves, which in a prime finite field is just exponentiating to p-1, right? And then you can merge the exponentiations and do b^((p-1)*e) mod p? So it would still be one builtin call?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it is logical though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are almost correct, if we do not have it, they will have to exponeniate with p-2 to get find the inverse.

That said, this is less efficient than a dedicated implementation, which may fail in the case if p is not prime. But, failing is not bad behavior in my opinion, as a dApp developer then can rely on this property. Whereas, the p-2 trick will just return an incorrect answer.

CIP-XXXX/README.md Outdated Show resolved Hide resolved
CIP-XXXX/README.md Outdated Show resolved Hide resolved
CIP-XXXX/README.md Outdated Show resolved Hide resolved
CIP-XXXX/README.md Outdated Show resolved Hide resolved
CIP-XXXX/README.md Outdated Show resolved Hide resolved
CIP-XXXX/README.md Outdated Show resolved Hide resolved
@rphair rphair changed the title CIP-???? | Modular Exponentiation Built-in for Plutus Core CIP-0109 | Modular Exponentiation Built-in for Plutus Core Jan 10, 2024
@rphair rphair changed the title CIP-0109 | Modular Exponentiation Built-in for Plutus Core CIP-0109? | Modular Exponentiation Built-in for Plutus Core Jan 10, 2024
Copy link
Collaborator

@rphair rphair left a comment

Choose a reason for hiding this comment

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

@perturbing you're all set for CIP number 109... please rename your CIP directory as well 🎉

CIP-XXXX/README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@rphair rphair left a comment

Choose a reason for hiding this comment

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

The feedback on this from Plutus reps has been good, and my own question (from last CIP meeting # 79, repeating #641 (review)), about CIP-0035 compliance, appears addressed by 52baecf and d120768 unless @michaelpj thinks anything is missing from Path to Active.

@perturbing this is coming up for review in today's CIP meeting (https://hackmd.io/@cip-editors/80) and I would say it's good to move to Last Check where the Plutus team & experts can give it further/final confirmation.

Copy link
Collaborator

@rphair rphair left a comment

Choose a reason for hiding this comment

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

(meant to include this fix in last review)

CIP-0109/README.md Outdated Show resolved Hide resolved
CIP-0109/README.md Outdated Show resolved Hide resolved
CIP-0109/README.md Outdated Show resolved Hide resolved
CIP-0109/README.md Outdated Show resolved Hide resolved
@rphair rphair added the Last Check This proposal has been reviewed and approved, staged for merging. label Jan 23, 2024
CIP-0109/README.md Outdated Show resolved Hide resolved
### Cost model
The computational impact of modular exponentiation is complexified by it having three arguments. That said, observe that the integers used can always be bound by the modulus. Preliminary [benchmarks](https://github.com/perturbing/expFast-bench/tree/cca69b842050de9523493d52c20384bc50c80b22) on the time consumption of this `integerPowMod` function show that it can be costed constant in the size of its first argument (the base) and linear in the other two.

## Rationale: how does this CIP achieve its goals?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to see a little more discussion in the Rationale.

Perhaps:

  • What would be other alternatives to this design?
  • Any backwards compatibility considerations?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mainly resolved with ebcd2ec.

CIP-0109/README.md Outdated Show resolved Hide resolved
CIP-0109/README.md Outdated Show resolved Hide resolved
rphair and others added 2 commits February 8, 2024 16:44
Editor consensus to resolve current deadlock from CIP meeting 81 in which Rationale was identified to be "thin" but still not being able to get supplementary writing from authors.
Co-authored-by: Ryan Williams <44342099+Ryun1@users.noreply.github.com>
Copy link
Collaborator

@rphair rphair left a comment

Choose a reason for hiding this comment

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

Inter- and post- CIP meeting editor's consensus produced ebcd2ec and confirmed f426619 which I've committed to avoid deadlock over formalities of document format & structure. 😇

Copy link
Collaborator

@Ryun1 Ryun1 left a comment

Choose a reason for hiding this comment

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

LGTM

@rphair rphair merged commit 089a154 into cardano-foundation:master Feb 8, 2024
Ryun1 added a commit to Ryun1/CIPs that referenced this pull request Feb 20, 2024
…foundation#641)

* add readme for modular exponentiation CIP

* add other authors

* remove unwanted semi-colon

* remove unwanted semi-colon

* add path to active

* add historic note, extra acceptance criteria and formatting

* assign official CIP number 109

* change directory name to match assigned cip number

* delete old CIP-XXXX dir

* pin github links

* add implementors

* formatting

* corrected missing CC license link

* formatting

* Update CIP-0109/README.md

* moved Rationale paragraph to Rationale from Motivation

Editor consensus to resolve current deadlock from CIP meeting 81 in which Rationale was identified to be "thin" but still not being able to get supplementary writing from authors.

* more detail in satisfaction of implementation requirements

Co-authored-by: Ryan Williams <44342099+Ryun1@users.noreply.github.com>

---------

Co-authored-by: Robert Phair <rphair@cosd.com>
Co-authored-by: Ryan Williams <44342099+Ryun1@users.noreply.github.com>
Ryun1 added a commit to Ryun1/CIPs that referenced this pull request Mar 6, 2024
…foundation#641)

* add readme for modular exponentiation CIP

* add other authors

* remove unwanted semi-colon

* remove unwanted semi-colon

* add path to active

* add historic note, extra acceptance criteria and formatting

* assign official CIP number 109

* change directory name to match assigned cip number

* delete old CIP-XXXX dir

* pin github links

* add implementors

* formatting

* corrected missing CC license link

* formatting

* Update CIP-0109/README.md

* moved Rationale paragraph to Rationale from Motivation

Editor consensus to resolve current deadlock from CIP meeting 81 in which Rationale was identified to be "thin" but still not being able to get supplementary writing from authors.

* more detail in satisfaction of implementation requirements

Co-authored-by: Ryan Williams <44342099+Ryun1@users.noreply.github.com>

---------

Co-authored-by: Robert Phair <rphair@cosd.com>
Co-authored-by: Ryan Williams <44342099+Ryun1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Plutus Proposals belonging to the 'Plutus' category. Last Check This proposal has been reviewed and approved, staged for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants