Skip to content

Commit

Permalink
fix: minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Feb 8, 2024
1 parent b99c8fd commit 9eeb7e6
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 115 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,17 @@ jobs:
name: "Test"
command: cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_card_game.test.ts

e2e-avm-simulator:
docker:
- image: aztecprotocol/alpine-build-image
resource_class: small
steps:
- *checkout
- *setup_env
- run:
name: "Test"
command: AVM_ENABLED=1 cond_spot_run_compose end-to-end 4 ./scripts/docker-compose.yml TEST=e2e_avm_simulator.test.ts

pxe:
docker:
- image: aztecprotocol/alpine-build-image
Expand Down Expand Up @@ -1275,6 +1286,7 @@ workflows:
- e2e-persistence: *e2e_test
- e2e-browser: *e2e_test
- e2e-card-game: *e2e_test
- e2e-avm-simulator: *e2e_test
- pxe: *e2e_test
- cli-docs-sandbox: *e2e_test
- guides-writing-an-account-contract: *e2e_test
Expand Down Expand Up @@ -1313,6 +1325,7 @@ workflows:
- e2e-persistence
- e2e-browser
- e2e-card-game
- e2e-avm-simulator
- pxe
- boxes-blank
- boxes-blank-react
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/logs/function_l2_logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { randomBytes } from 'crypto';
import { LogType } from './log_type.js';
import { UnencryptedL2Log } from './unencrypted_l2_log.js';

// ???????????????????????????????????
/**
* Data container of logs emitted in 1 function invocation (corresponds to 1 kernel iteration).
*/
Expand Down
1 change: 1 addition & 0 deletions yarn-project/end-to-end/scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
WS_BLOCK_CHECK_INTERVAL_MS: 50
PXE_BLOCK_POLLING_INTERVAL_MS: 50
ARCHIVER_VIEM_POLLING_INTERVAL_MS: 500
AVM_ENABLED: ${AVM_ENABLED:-}
ports:
- '8080:8080'

Expand Down
10 changes: 6 additions & 4 deletions yarn-project/end-to-end/src/e2e_avm_simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { DebugLogger, Fr, Wallet } from '@aztec/aztec.js';
import { AvmTestContract } from '@aztec/noir-contracts';

import { setup } from './fixtures/utils.js';

process.env.AVM_ENABLED = 'absofrigginlutely';

describe('e2e_nested_contract', () => {
let wallet: Wallet;
let logger: DebugLogger;
let teardown: () => Promise<void>;

beforeEach(async () => {
process.env.AVM_ENABLED = 'absofrigginlutely';
({ teardown, pxe, wallet, logger } = await setup());
({ teardown, wallet, logger } = await setup());
}, 100_000);

afterEach(() => teardown());
Expand All @@ -23,11 +26,10 @@ describe('e2e_nested_contract', () => {
it('Calls an avm contract', async () => {
const a = new Fr(1);
const b = new Fr(2);
// const expectedResult = a.add(b);

// TODO: fix type gen for avm_addArgsReturn - incorrect number of args
logger('Calling avm_addArgsReturn...');
await avmContact.methods.avm_addArgsReturn(a, b).send().wait();
logger('Success');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ import {
} from '@aztec/simulator';
import { MerkleTreeOperations } from '@aztec/world-state';

import { env } from 'process';

import { getVerificationKeys } from '../mocks/verification_keys.js';
import { PublicProver } from '../prover/index.js';
import { PublicKernelCircuitSimulator } from '../simulator/index.js';
import { FailedTx } from './processed_tx.js';
import { env } from 'process';

/**
* A phase manager is responsible for performing/rolling back a phase of a transaction.
Expand Down Expand Up @@ -159,11 +160,11 @@ export abstract class AbstractPhaseManager {
const current = executionStack.pop()!;
const isExecutionRequest = !isPublicExecutionResult(current);

// TODO: get this from the environment
// NOTE: temporary glue to incorporate avm execution calls
const simulator = (env.AVM_ENABLED
? (execution: PublicExecution, globalVariables: any) => this.publicExecutor.simulateAvm(execution, globalVariables)
: (execution: PublicExecution, globalVariables: any) => this.publicExecutor.simulate(execution, globalVariables));
const simulator = (execution: PublicExecution, globalVariables: GlobalVariables) =>
env.AVM_ENABLED
? this.publicExecutor.simulateAvm(execution, globalVariables)
: this.publicExecutor.simulate(execution, globalVariables);

const result = isExecutionRequest ? await simulator(current, this.globalVariables) : current;

Expand Down
8 changes: 4 additions & 4 deletions yarn-project/simulator/src/avm/avm_execution_environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AvmExecutionEnvironment {

public readonly calldata: Fr[],

public readonly temporaryFunctionSelector: FunctionSelector
public readonly temporaryFunctionSelector: FunctionSelector,
) {}

public deriveEnvironmentForNestedCall(address: AztecAddress, calldata: Fr[]): AvmExecutionEnvironment {
Expand All @@ -54,7 +54,7 @@ export class AvmExecutionEnvironment {
this.isStaticCall,
this.isDelegateCall,
/*calldata=*/ calldata,
this.temporaryFunctionSelector
this.temporaryFunctionSelector,
);
}

Expand All @@ -73,7 +73,7 @@ export class AvmExecutionEnvironment {
/*isStaticCall=*/ true,
this.isDelegateCall,
/*calldata=*/ calldata,
this.temporaryFunctionSelector
this.temporaryFunctionSelector,
);
}

Expand All @@ -92,7 +92,7 @@ export class AvmExecutionEnvironment {
this.isStaticCall,
/*isDelegateCall=*/ true,
/*calldata=*/ calldata,
this.temporaryFunctionSelector
this.temporaryFunctionSelector,
);
}
}
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/avm/fixtures/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GlobalVariables } from '@aztec/circuits.js';
import { FunctionSelector } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { FunctionSelector } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';

import { mock } from 'jest-mock-extended';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/avm/journal/host_storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommitmentsDB, PublicContractsDB, PublicStateDB } from '../../index.js';
import { CommitmentsDB, PublicContractsDB, PublicStateDB } from '../../public/db.js';

/**
* Host storage
Expand Down
28 changes: 0 additions & 28 deletions yarn-project/simulator/src/avm/temporary_executor.ts

This file was deleted.

110 changes: 110 additions & 0 deletions yarn-project/simulator/src/avm/temporary_executor_migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// All code in this file needs to die once the public executor is phased out.
import { FunctionL2Logs } from '@aztec/circuit-types';
import {
ContractStorageRead,
ContractStorageUpdateRequest,
GlobalVariables,
SideEffect,
SideEffectLinkedToNoteHash,
} from '@aztec/circuits.js';
import { Fr } from '@aztec/foundation/fields';

import { PublicExecution, PublicExecutionResult } from '../public/execution.js';
import { AvmExecutionEnvironment } from './avm_execution_environment.js';
import { AvmContractCallResults } from './avm_message_call_result.js';
import { JournalData } from './journal/journal.js';

/** Temporary Method
*
* Convert a PublicExecution(Environment) object to an AvmExecutionEnvironment
*
* @param current
* @param globalVariables
* @returns
*/
export function temporaryMapToExecutionEnvironment(
current: PublicExecution,
globalVariables: GlobalVariables,
): AvmExecutionEnvironment {
// Function selector is included temporarily until noir codegens public contract bytecode in a single blob
return new AvmExecutionEnvironment(
current.contractAddress,
current.callContext.storageContractAddress,
current.callContext.msgSender, // TODO: origin is not available
current.callContext.msgSender,
current.callContext.portalContractAddress,
/*feePerL1Gas=*/ Fr.zero(),
/*feePerL2Gas=*/ Fr.zero(),
/*feePerDaGas=*/ Fr.zero(),
/*contractCallDepth=*/ Fr.zero(),
globalVariables,
current.callContext.isStaticCall,
current.callContext.isDelegateCall,
current.args,
current.functionData.selector,
);
}

/** Temporary Method
*
* Convert the result of an AVM contract call to a PublicExecutionResult for the public kernel
*
* @param execution
* @param newWorldState
* @param result
* @returns
*/
export function temporaryMapAvmReturnTypes(
execution: PublicExecution,
newWorldState: JournalData,
result: AvmContractCallResults,
): PublicExecutionResult {
const newCommitments = newWorldState.newNoteHashes.map(noteHash => new SideEffect(noteHash, Fr.zero()));

const contractStorageReads: ContractStorageRead[] = [];
const reduceStorageReadRequests = (contractAddress: bigint, storageReads: Map<bigint, Fr[]>) => {
return storageReads.forEach((innerArray, key) => {
innerArray.forEach(value => {
contractStorageReads.push(new ContractStorageRead(new Fr(key), new Fr(value), 0));
});
});
};
newWorldState.storageReads.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) =>
reduceStorageReadRequests(address, storageMap),
);

const contractStorageUpdateRequests: ContractStorageUpdateRequest[] = [];
const reduceStorageUpdateRequests = (contractAddress: bigint, storageUpdateRequests: Map<bigint, Fr[]>) => {
return storageUpdateRequests.forEach((innerArray, key) => {
innerArray.forEach(value => {
contractStorageUpdateRequests.push(
new ContractStorageUpdateRequest(new Fr(key), /*TODO: old value not supported */ Fr.zero(), new Fr(value), 0),
);
});
});
};
newWorldState.storageWrites.forEach((storageMap: Map<bigint, Fr[]>, address: bigint) =>
reduceStorageUpdateRequests(address, storageMap),
);

const returnValues = result.output;

// TODO(follow up in pr tree): NOT SUPPORTED YET, make sure hashing and log resolution is done correctly
// Disabled.
const nestedExecutions: PublicExecutionResult[] = [];
const newNullifiers: SideEffectLinkedToNoteHash[] = [];
const unencryptedLogs = FunctionL2Logs.empty();
const newL2ToL1Messages = newWorldState.newL1Messages.map(() => Fr.zero());

return {
execution,
newCommitments,
newL2ToL1Messages,
newNullifiers,
contractStorageReads,
contractStorageUpdateRequests,
returnValues,
nestedExecutions,
unencryptedLogs,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createDebugLogger } from '@aztec/foundation/log';
import { extractReturnWitness } from '../acvm/deserialize.js';
import { Oracle, acvm, extractCallStack, toACVMWitness } from '../acvm/index.js';
import { ExecutionError } from '../common/errors.js';
import { AcirSimulator } from '../index.js';
import { AcirSimulator } from './simulator.js';
import { ViewDataOracle } from './view_data_oracle.js';

// docs:start:execute_unconstrained_function
Expand Down
Loading

0 comments on commit 9eeb7e6

Please sign in to comment.