forked from visoftsolutions/noir_rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simulator utils cleanup (AztecProtocol#4507)
Cleanup of utils in simulator package.
- Loading branch information
Showing
3 changed files
with
24 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,18 @@ | ||
import { GrumpkinPrivateKey } from '@aztec/circuits.js'; | ||
import { Grumpkin } from '@aztec/circuits.js/barretenberg'; | ||
import { pedersenHash } from '@aztec/foundation/crypto'; | ||
import { Fr } from '@aztec/foundation/fields'; | ||
|
||
/** | ||
* A point in the format that Aztec.nr uses. | ||
*/ | ||
export type NoirPoint = { | ||
/** The x coordinate. */ | ||
x: bigint; | ||
/** The y coordinate. */ | ||
y: bigint; | ||
}; | ||
|
||
/** | ||
* Computes the resulting storage slot for an entry in a mapping. | ||
* @param mappingSlot - The slot of the mapping within state. | ||
* @param owner - The key of the mapping. | ||
* @param key - The key of the mapping. | ||
* @returns The slot in the contract storage where the value is stored. | ||
*/ | ||
export function computeSlotForMapping(mappingSlot: Fr, owner: NoirPoint | Fr) { | ||
const isFr = (owner: NoirPoint | Fr): owner is Fr => typeof (owner as Fr).value === 'bigint'; | ||
const ownerField = isFr(owner) ? owner : new Fr(owner.x); | ||
|
||
return Fr.fromBuffer(pedersenHash([mappingSlot, ownerField].map(f => f.toBuffer()))); | ||
} | ||
|
||
/** | ||
* Computes the public key for a private key. | ||
* @param privateKey - The private key. | ||
* @param grumpkin - The grumpkin instance. | ||
* @returns The public key. | ||
*/ | ||
export function toPublicKey(privateKey: GrumpkinPrivateKey, grumpkin: Grumpkin): NoirPoint { | ||
const point = grumpkin.mul(Grumpkin.generator, privateKey); | ||
return { | ||
x: point.x.value, | ||
y: point.y.value, | ||
}; | ||
export function computeSlotForMapping( | ||
mappingSlot: Fr, | ||
key: { | ||
/** Serialize to a field. */ | ||
toField: () => Fr; | ||
}, | ||
) { | ||
return Fr.fromBuffer(pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer()))); | ||
} |