Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion yarn-project/foundation/src/curves/bn254/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type DerivedField<T extends BaseField> = {
*/
abstract class BaseField {
static SIZE_IN_BYTES = 32;
private static readonly ZERO_BUFFER = Buffer.alloc(BaseField.SIZE_IN_BYTES);
private readonly asBigInt: bigint;

/**
Expand Down Expand Up @@ -67,7 +68,10 @@ abstract class BaseField {
* Converts the bigint to a Buffer.
*/
toBuffer(): Buffer {
return toBufferBE(this.asBigInt, 32);
if (this.asBigInt === 0n) {
return BaseField.ZERO_BUFFER;
}
return toBufferBE(this.asBigInt, BaseField.SIZE_IN_BYTES);
}

toString(): `0x${string}` {
Expand Down
Loading