We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dcf7354 commit c7abfa8Copy full SHA for c7abfa8
1 file changed
yarn-project/foundation/src/curves/bn254/field.ts
@@ -25,6 +25,7 @@ type DerivedField<T extends BaseField> = {
25
*/
26
abstract class BaseField {
27
static SIZE_IN_BYTES = 32;
28
+ private static readonly ZERO_BUFFER = Buffer.alloc(BaseField.SIZE_IN_BYTES);
29
private readonly asBigInt: bigint;
30
31
/**
@@ -67,7 +68,10 @@ abstract class BaseField {
67
68
* Converts the bigint to a Buffer.
69
70
toBuffer(): Buffer {
- return toBufferBE(this.asBigInt, 32);
71
+ if (this.asBigInt === 0n) {
72
+ return BaseField.ZERO_BUFFER;
73
+ }
74
+ return toBufferBE(this.asBigInt, BaseField.SIZE_IN_BYTES);
75
}
76
77
toString(): `0x${string}` {
0 commit comments