-
Notifications
You must be signed in to change notification settings - Fork 234
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
chore: simulator utils cleanup #4507
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 |
---|---|---|
@@ -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. */ | ||
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. Should there not be some limiter on the length of the key? 🤔 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. Good point. Added the check by instead accepting object with |
||
toField: () => Fr; | ||
}, | ||
) { | ||
return Fr.fromBuffer(pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer()))); | ||
} |
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.
Was this simply unused?
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.
Yes