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

Discuss: should we panic when powering 0 by 0? #303

Closed
wants to merge 1 commit into from

Conversation

weikengchen
Copy link
Member

@weikengchen weikengchen commented Jul 4, 2021

Description

This is half PR half discussion.

For pow function, there is a corner case when the base is zero and the pow is also zero.

There are two ways to handle it:

  1. panic, as in this PR
  2. let it be "1", which is indeed an accepted practice in some fields.

Note that this treatment is sort of for "soundness". It is hard to imagine a concrete application where the developer wants to power a value by "0".

Any opinions? Note that letting it be "1" is simpler.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Re-reviewed Files changed in the Github PR explorer

not ready:

  • Added a relevant changelog entry to the Pending section in CHANGELOG.md

@weikengchen
Copy link
Member Author

Note: Rust itself considers 0^0 = 1. I think we just need to consider whether it will ever cause soundness problems in any application. Note that if we panic when 0^0, it may cause additional issues that the program may panic unnecessarily.

if exp == 0 {
     return 1;
}

@weikengchen weikengchen marked this pull request as draft July 4, 2021 08:05
@ValarDragon
Copy link
Member

ValarDragon commented Jul 6, 2021

I think setting it to 1 makes sense personally. I think risk of panic for a core algebraic routine will cause more error handling / cognitive overhead code bloat, for something that seems like a very low risk error to get introduced in natural code.

(Also AFAIK, 0^0 = 1 is relatively common in algebra settings)

@weikengchen weikengchen closed this Jul 6, 2021
@weikengchen
Copy link
Member Author

I think let us settle that 0^0 = 1. I will update arkworks-rs/r1cs-std#72 accordingly.

@weikengchen weikengchen deleted the pow-zero-by-zero branch July 6, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants