Skip to content

Commit

Permalink
refactor: renaming stev (#1292)
Browse files Browse the repository at this point in the history
# Description

Fixes #1229
  • Loading branch information
benesjan authored Jul 31, 2023
1 parent abcf81c commit 31d290a
Show file tree
Hide file tree
Showing 23 changed files with 508 additions and 497 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FUNCTION_SELECTOR_NUM_BYTES } from '@aztec/circuits.js';
import { computeFunctionSelector } from '@aztec/foundation/abi';

export const computeNoteHashAndNullifierSignature = 'stev(field,field,field,array)';
export const computeNoteHashAndNullifierSignature = 'compute_note_hash_and_nullifier(field,field,field,array)';

export const computeNoteHashAndNullifierSelector = computeFunctionSelector(
computeNoteHashAndNullifierSignature,
Expand Down
96 changes: 48 additions & 48 deletions yarn-project/aztec.js/src/abis/ecdsa_account_contract.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,54 @@
{
"name": "EcdsaAccount",
"functions": [
{
"name": "compute_note_hash_and_nullifier",
"functionType": "unconstrained",
"isInternal": false,
"parameters": [
{
"name": "contract_address",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "nonce",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "storage_slot",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "preimage",
"type": {
"kind": "array",
"length": 5,
"type": {
"kind": "field"
}
},
"visibility": "private"
}
],
"returnTypes": [
{
"kind": "array",
"length": 4,
"type": {
"kind": "field"
}
}
]
},
{
"name": "constructor",
"functionType": "secret",
Expand Down Expand Up @@ -100,54 +148,6 @@
}
],
"returnTypes": []
},
{
"name": "stev",
"functionType": "unconstrained",
"isInternal": false,
"parameters": [
{
"name": "contract_address",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "nonce",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "storage_slot",
"type": {
"kind": "field"
},
"visibility": "private"
},
{
"name": "preimage",
"type": {
"kind": "array",
"length": 5,
"type": {
"kind": "field"
}
},
"visibility": "private"
}
],
"returnTypes": [
{
"kind": "array",
"length": 4,
"type": {
"kind": "field"
}
}
]
}
]
}
100 changes: 50 additions & 50 deletions yarn-project/noir-contracts/src/artifacts/easy_zk_token_contract.json

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions yarn-project/noir-contracts/src/artifacts/ecdsa_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions yarn-project/noir-contracts/src/artifacts/zk_token_contract.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract EasyZkToken {
log::emit_unencrypted_log,
note::{
note_header::NoteHeader,
utils::compute_note_hash_and_nullifier,
utils as note_utils,
},
};

Expand Down Expand Up @@ -100,8 +100,11 @@ contract EasyZkToken {
balance_utils::get_balance(balances.at(owner).storage_slot)
}

unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader { contract_address, nonce, storage_slot };
compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ contract EcdsaAccount {
use dep::aztec::types::point::Point;

use dep::aztec::constants_gen::MAX_NOTE_FIELDS_LENGTH;
use dep::aztec::note::utils::compute_note_hash_and_nullifier;
use dep::aztec::note::note_header::NoteHeader;
use dep::aztec::note::{
note_header::{NoteHeader},
utils as note_utils,
};

use crate::storage::Storage;
use crate::ecdsa_public_key_note::EcdsaPublicKeyNote;
Expand Down Expand Up @@ -92,9 +94,12 @@ contract EcdsaAccount {
context.finish()
}

unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; ECDSA_PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {
assert(storage_slot == 1);
let note_header = NoteHeader { contract_address, nonce, storage_slot };
compute_note_hash_and_nullifier(EcdsaPublicKeyNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(EcdsaPublicKeyNoteInterface, note_header, preimage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract NonNativeToken {
},
note::{
note_header::NoteHeader,
utils::compute_note_hash_and_nullifier,
utils as note_utils,
},
};

Expand Down Expand Up @@ -324,11 +324,11 @@ contract NonNativeToken {
balance_utils::get_balance(owner_balance.storage_slot)
}

// stev function needs to be defined by every contract producing logs. Having it in all the contracts gives us the ability to
// compute the note hash and nullifier differently for different kind of notes.
// Note: "stev" is just a placeholder name before we come up with a better one.
unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader { contract_address, nonce, storage_slot };
compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract PendingCommitments {
note_getter::NoteGetterOptions,
note_getter_options::Sort,
note_header::NoteHeader,
utils::compute_note_hash_and_nullifier,
utils as note_utils,
};
use dep::aztec::types::point::Point;
use dep::aztec::state_vars::map::Map;
Expand Down Expand Up @@ -236,11 +236,11 @@ contract PendingCommitments {
//) -> distinct pub abi::PrivateCircuitPublicInputs {
//}

// stev function needs to be defined by every contract producing logs. Having it in all the contracts gives us the ability to
// compute the note hash and nullifier differently for different kind of notes.
// Note: "stev" is just a placeholder name before we come up with a better one.
unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader { contract_address, nonce, storage_slot };
compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract PokeableToken {
use dep::aztec::note::{
note_getter::NoteGetterOptions,
note_header::{NoteHeader},
utils::compute_note_hash_and_nullifier,
utils as note_utils,
};
use dep::aztec::types::point::Point;
use dep::aztec::oracle::get_public_key::get_public_key_non_contract_account;
Expand Down Expand Up @@ -126,15 +126,15 @@ contract PokeableToken {
balance_utils::get_balance(sender_balance.storage_slot)
}

// stev function needs to be defined by every contract producing logs. Having it in all the contracts gives us the ability to
// compute the note hash and nullifier differently for different kind of notes.
// Note: "stev" is just a placeholder name before we come up with a better one.
unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader { contract_address, nonce, storage_slot };
if (storage_slot == 1) | (storage_slot == 2) {
compute_note_hash_and_nullifier(AddressNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(AddressNoteInterface, note_header, preimage)
} else {
compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract SchnorrMultiKeyAccount {
use dep::aztec::oracle::get_public_key::get_public_key;
use dep::aztec::types::vec::BoundedVec;
use dep::aztec::types::point::Point;
use dep::aztec::note::utils::compute_note_hash_and_nullifier;
use dep::aztec::note::utils as note_utils;
use dep::aztec::note::note_header::NoteHeader;
use dep::aztec::constants_gen::MAX_NOTE_FIELDS_LENGTH;
use dep::aztec::constants_gen::GENERATOR_INDEX__CONTRACT_ADDRESS;
Expand Down Expand Up @@ -85,9 +85,12 @@ contract SchnorrMultiKeyAccount {
context.finish()
}

unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {
// Computes notes hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; PUBLIC_KEY_NOTE_LEN]) -> [Field; 4] {
assert(storage_slot == 1);
let note_header = NoteHeader { contract_address, nonce, storage_slot };
compute_note_hash_and_nullifier(PublicKeyNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(PublicKeyNoteInterface, note_header, preimage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract ZkToken {
use dep::aztec::context::Context;
use dep::aztec::note::{
note_header::{NoteHeader},
utils::compute_note_hash_and_nullifier,
utils as note_utils,
};
use dep::aztec::types::point::Point;
use dep::aztec::state_vars::map::Map;
Expand Down Expand Up @@ -166,15 +166,15 @@ contract ZkToken {
balance_utils::get_balance(owner_balance.storage_slot)
}

// stev function needs to be defined by every contract producing logs. Having it in all the contracts gives us the ability to
// compute the note hash and nullifier differently for different kind of notes.
// Note: "stev" is just a placeholder name before we come up with a better one.
unconstrained fn stev(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
// Computes note hash and nullifier.
// Note 1: Needs to be defined by every contract producing logs.
// Note 2: Having it in all the contracts gives us the ability to compute the note hash and nullifier differently for different kind of notes.
unconstrained fn compute_note_hash_and_nullifier(contract_address: Field, nonce: Field, storage_slot: Field, preimage: [Field; VALUE_NOTE_LEN]) -> [Field; 4] {
let note_header = NoteHeader { contract_address, nonce, storage_slot };
if (storage_slot == 2) {
compute_note_hash_and_nullifier(ClaimNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ClaimNoteInterface, note_header, preimage)
} else {
compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
note_utils::compute_note_hash_and_nullifier(ValueNoteInterface, note_header, preimage)
}
}
}
18 changes: 9 additions & 9 deletions yarn-project/noir-contracts/src/types/easy_zk_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ export class EasyZkTokenContract extends Contract {

/** Type-safe wrappers for the public methods exposed by the contract. */
public methods!: {
/** compute_note_hash_and_nullifier(contract_address: field, nonce: field, storage_slot: field, preimage: array) */
compute_note_hash_and_nullifier: ((
contract_address: Fr | bigint | number | { toField: () => Fr },
nonce: Fr | bigint | number | { toField: () => Fr },
storage_slot: Fr | bigint | number | { toField: () => Fr },
preimage: (Fr | bigint | number | { toField: () => Fr })[],
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;

/** getBalance(owner: field) */
getBalance: ((owner: Fr | bigint | number | { toField: () => Fr }) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;
Expand All @@ -71,15 +80,6 @@ export class EasyZkTokenContract extends Contract {
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;

/** stev(contract_address: field, nonce: field, storage_slot: field, preimage: array) */
stev: ((
contract_address: Fr | bigint | number | { toField: () => Fr },
nonce: Fr | bigint | number | { toField: () => Fr },
storage_slot: Fr | bigint | number | { toField: () => Fr },
preimage: (Fr | bigint | number | { toField: () => Fr })[],
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;

/** transfer(amount: integer, sender: field, recipient: field) */
transfer: ((
amount: bigint | number,
Expand Down
18 changes: 9 additions & 9 deletions yarn-project/noir-contracts/src/types/ecdsa_account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ export class EcdsaAccountContract extends Contract {

/** Type-safe wrappers for the public methods exposed by the contract. */
public methods!: {
/** compute_note_hash_and_nullifier(contract_address: field, nonce: field, storage_slot: field, preimage: array) */
compute_note_hash_and_nullifier: ((
contract_address: Fr | bigint | number | { toField: () => Fr },
nonce: Fr | bigint | number | { toField: () => Fr },
storage_slot: Fr | bigint | number | { toField: () => Fr },
preimage: (Fr | bigint | number | { toField: () => Fr })[],
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;

/** entrypoint(payload: struct, signature: array) */
entrypoint: ((
payload: {
Expand All @@ -67,14 +76,5 @@ export class EcdsaAccountContract extends Contract {
signature: (bigint | number)[],
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;

/** stev(contract_address: field, nonce: field, storage_slot: field, preimage: array) */
stev: ((
contract_address: Fr | bigint | number | { toField: () => Fr },
nonce: Fr | bigint | number | { toField: () => Fr },
storage_slot: Fr | bigint | number | { toField: () => Fr },
preimage: (Fr | bigint | number | { toField: () => Fr })[],
) => ContractFunctionInteraction) &
Pick<ContractMethod, 'selector'>;
};
}
Loading

0 comments on commit 31d290a

Please sign in to comment.