Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Aug 24, 2023
1 parent aa68f96 commit fb4c8b7
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 42 deletions.
9 changes: 0 additions & 9 deletions yarn-project/acir-simulator/src/acvm/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ export function frToBoolean(fr: Fr): boolean {
return buf[buf.length - 1] !== 0;
}

/**
* Converts a field to a function selector.
* @param fr - The field to convert.
* @returns The function selector.
*/
export function frToSelector(fr: Fr): FunctionSelector {
return FunctionSelector.fromBuffer(fr.toBuffer().slice(-4));
}

/**
* Extracts the return fields of a given partial witness.
* @param acir - The bytecode of the function.
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
import { to2Fields } from '@aztec/foundation/serialize';
import { FunctionL2Logs, NotePreimage, NoteSpendingInfo } from '@aztec/types';

import { extractPrivateCircuitPublicInputs, frToAztecAddress, frToSelector } from '../acvm/deserialize.js';
import { extractPrivateCircuitPublicInputs, frToAztecAddress } from '../acvm/deserialize.js';
import {
ZERO_ACVM_FIELD,
acvm,
Expand Down Expand Up @@ -132,7 +132,7 @@ export class PrivateFunctionExecution {

const childExecutionResult = await this.callPrivateFunction(
frToAztecAddress(contractAddress),
frToSelector(functionSelector),
FunctionSelector.fromField(functionSelector),
fromACVMField(acvmArgsHash),
this.callContext,
this.curve,
Expand All @@ -157,7 +157,7 @@ export class PrivateFunctionExecution {
enqueuePublicFunctionCall: async ([acvmContractAddress], [acvmFunctionSelector], [acvmArgsHash]) => {
const enqueuedRequest = await this.enqueuePublicFunctionCall(
frToAztecAddress(fromACVMField(acvmContractAddress)),
frToSelector(fromACVMField(acvmFunctionSelector)),
FunctionSelector.fromField(fromACVMField(acvmFunctionSelector)),
this.context.packedArgsCache.unpack(fromACVMField(acvmArgsHash)),
this.callContext,
);
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/acir-simulator/src/public/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
convertACVMFieldToBuffer,
extractPublicCircuitPublicInputs,
frToAztecAddress,
frToSelector,
fromACVMField,
toACVMField,
toACVMWitness,
Expand Down Expand Up @@ -118,7 +117,7 @@ export class PublicExecutor {
this.log(`Public function call: addr=${address} selector=${functionSelector} args=${args.join(',')}`);
const childExecutionResult = await this.callPublicFunction(
frToAztecAddress(fromACVMField(address)),
frToSelector(fromACVMField(functionSelector)),
FunctionSelector.fromField(fromACVMField(functionSelector)),
args,
execution.callContext,
globalVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function buildPayload(
// eslint-disable-next-line camelcase
flattened_args_hashes: packedArguments.map(args => args.hash),
// eslint-disable-next-line camelcase
flattened_selectors: calls.map(call => Fr.fromBuffer(call.functionData.functionSelector.toBuffer())),
flattened_selectors: calls.map(call => call.functionData.functionSelector.toField()),
// eslint-disable-next-line camelcase
flattened_targets: calls.map(call => call.to.toField()),
nonce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {
// 4. Send L2 to L1 message to withdraw funds and another message to swap assets.
logger('Send L2 tx to withdraw WETH to uniswap portal and send message to swap assets on L1');
// recipient is the uniswap portal
const selector = Fr.fromBuffer(wethL2Contract.methods.withdraw.selector.toBuffer());
const selector = wethL2Contract.methods.withdraw.selector.toField();
const minimumOutputAmount = 0n;

const withdrawTx = uniswapL2Contract.methods
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/cbind/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export {
G1AffineElement,
NewContractData,
FunctionData,
FunctionSelector,
OptionallyRevealedData,
PublicDataRead,
PublicDataUpdateRequest,
Expand All @@ -53,6 +52,7 @@ export {
Coordinate,
GlobalVariables,
} from '../structs/index.js';
export { FunctionSelector } from '@aztec/foundation/abi';

/**
* A pointer to a Prover object in WebAssembly memory.
Expand Down
12 changes: 2 additions & 10 deletions yarn-project/circuits.js/src/contract/contract_deployment_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ import {
computeVarArgsHash,
hashConstructor,
} from '@aztec/circuits.js/abis';
import { ContractAbi, encodeArguments } from '@aztec/foundation/abi';
import { ContractAbi, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';

import {
CircuitsWasm,
CompleteAddress,
DeploymentInfo,
Fr,
FunctionData,
FunctionSelector,
PublicKey,
} from '../index.js';
import { CircuitsWasm, CompleteAddress, DeploymentInfo, Fr, FunctionData, PublicKey } from '../index.js';
import { generateFunctionLeaves, hashVKStr, isConstructor } from './contract_tree/contract_tree.js';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
CircuitsWasm,
ContractFunctionDao,
Fr,
FunctionData,
FunctionLeafPreimage,
FunctionSelector,
} from '@aztec/circuits.js';
import { CircuitsWasm, ContractFunctionDao, Fr, FunctionData, FunctionLeafPreimage } from '@aztec/circuits.js';
import { computeFunctionLeaf, hashVK } from '@aztec/circuits.js/abis';
import { FunctionType } from '@aztec/foundation/abi';
import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';

/**
* Computes the hash of a hex-encoded string representation of a verification key (vk).
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/structs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export * from './tx_request.js';
export * from './tx_context.js';
export * from './verification_key.js';
export * from './function_leaf_preimage.js';
export * from '../../../foundation/src/abi/function_selector.js';
export * from './aggregation_object.js';
export * from './membership_witness.js';
export * from './read_request_membership_witness.js';
Expand All @@ -33,3 +32,4 @@ export * from '@aztec/foundation/eth-address';

export * from '@aztec/foundation/fields';
export * from '@aztec/foundation/aztec-address';
export { FunctionSelector } from '@aztec/foundation/abi';
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"path": "../foundation"
}
],
"include": ["src", "../foundation/src/abi/function_selector.ts"]
"include": ["src"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ describe('e2e_pending_commitments_contract', () => {
.test_insert2_then_get2_then_nullify1_all_in_nested_calls(
mintAmount,
owner,
Fr.fromBuffer(deployedContract.methods.insert_note.selector),
Fr.fromBuffer(deployedContract.methods.get_then_nullify_note.selector),
deployedContract.methods.insert_note.selector.toField(),
deployedContract.methods.get_then_nullify_note.selector.toField(),
)
.send({ origin: owner });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ describe('uniswap_trade_on_l1_from_l2', () => {

// 4. Send L2 to L1 message to withdraw funds and another message to swap assets.
logger('Send L2 tx to withdraw WETH to uniswap portal and send message to swap assets on L1');
const selector = Fr.fromBuffer(wethCrossChainHarness.l2Contract.methods.withdraw.selector);
const selector = wethCrossChainHarness.l2Contract.methods.withdraw.selector.toField();
const minimumOutputAmount = 0;

const withdrawTx = uniswapL2Contract.methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function isPrivateCall(functionType: FunctionType) {
function generateCallStatement(selector: FunctionSelector, functionType: FunctionType) {
const callMethod = isPrivateCall(functionType) ? 'call_private_function' : 'call_public_function';
return `
context.${callMethod}(self.address, ${selector.toString()}, serialised_args)`;
context.${callMethod}(self.address, 0x${selector.toString()}, serialised_args)`;
}

/**
Expand Down

0 comments on commit fb4c8b7

Please sign in to comment.