-
-
Notifications
You must be signed in to change notification settings - Fork 63
tests: koala and babybear field ops #580
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,96 @@ proc main() = | |
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| # BabyBear --------------------------------- | ||
| block: | ||
| # "Little-endian" - 0 | ||
| let x = 0'u64 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[BabyBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - 1 | ||
| let x = 1'u64 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[BabyBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - 2^15 | ||
| let x = 1'u64 shl 15 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[BabyBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - p-1 | ||
| let x = 2013265921'u64 - 1 | ||
mratsim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[BabyBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| # KoalaBear --------------------------------- | ||
| block: | ||
| # "Little-endian" - 0 | ||
| let x = 0'u64 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[KoalaBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - 1 | ||
| let x = 1'u64 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[KoalaBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - 2^15 | ||
| let x = 1'u64 shl 15 | ||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[KoalaBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
| block: | ||
| # "Little-endian" - p-1 | ||
| let x = 2130706433'u64 - 1 | ||
mratsim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let x_bytes = cast[array[8, byte]](x) | ||
| var f: Fp[KoalaBear] | ||
| f.fromUint(x) | ||
|
|
||
| var r_bytes: array[8, byte] | ||
| marshal(r_bytes, f, littleEndian) | ||
| check: x_bytes == r_bytes | ||
|
|
||
|
Comment on lines
+49
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a lot of repeated code in the IO tests for BabyBear and KoalaBear. You could reduce this duplication by creating a helper procedure. This would make the tests more concise and easier to maintain. Here's an example of a helper procedure: proc checkFieldIO[F: static Algebra](value: uint64) =
let x_bytes = cast[array[8, byte]](value)
var f: Fp[F]
f.fromUint(value)
var r_bytes: array[8, byte]
marshal(r_bytes, f, littleEndian)
check: x_bytes == r_bytesThen you could refactor the test blocks like this: # BabyBear ---------------------------------
block:
# "Little-endian" - 0
checkFieldIO[BabyBear](0'u64)
block:
# "Little-endian" - 1
checkFieldIO[BabyBear](1'u64)
# ... and so on for other test cases and KoalaBear.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid suggestion by gemini |
||
| # Mersenne 61 --------------------------------- | ||
| block: | ||
| # "Little-endian" - 0 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests for BabyBear and KoalaBear contain a lot of duplicated code for addition, subtraction, and multiplication. This can be refactored using helper procedures to make the tests more concise and maintainable.
Here are some example helper procedures you could add:
With these helpers, the tests become much simpler, for example:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a valid suggestion by Gemini