Skip to content
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: prep for switching AVM to checkpointed native trees - TS test cleanup and refactors #12023

Merged
merged 21 commits into from
Feb 19, 2025

Conversation

dbanks12
Copy link
Collaborator

@dbanks12 dbanks12 commented Feb 15, 2025

This PR is mostly setup for switching the AVM to use checkpointed native trees. Originally I had that in the same branch, but there were enough of these prerequisite changes to pull them out.

Orchestrator testing

prover-client's TestContext no longer mocks AVM simulation.

Context: while trying to transition the AVM to use native checkpointed trees, I ran into issues with the orchestrator public functions tests because the public processor will no longer update the trees for public functions. So, I think we should stop mocking the AVM simulation for these tests and let the AVM do its tree updates. We can then do two types of tests:

  1. A quick test that doesn't actually deploy/run any real contract functions and instead tests the orchestrator with a mocked/garbage TX that has 1 revertible enqueued call. The AVM will fail to retrieve it's bytecode, but the TX can still be included. orchestrator_public_functions.test.ts now does this.
  2. A real test that creates TXs that actually do a bunch of real token operations via non-revertible and revertible enqueued calls. orchestrator_multi_public_functions.test.ts now does this.

AVM & PublicProcessor testing

  • PublicTxSimulationTester lets you createTx separately from simulateTx (useful for testing PublicProcessor)
  • Add PublicTxSimulator test for avm bulk test
  • Add a PublicProcessor test of the token contract (construct, mint, many transfers)
  • Consolidate some duplicate helper functions in simulator/src/avm and simulator/src/public
  • Simplify process of registering/deploying contracts via avm *Tester classes, and optional contract address nullifier insertion
  • Contract Updates test now use the tester's register*() function instead of manually constructing contract classes and instances
  • Remove unused function from avm test contract

Misc

  • Making contract classes for tests is now deterministic (no more random public keys)
  • Use new/proper sha256 in benchmarking test contract

@dbanks12 dbanks12 marked this pull request as ready for review February 18, 2025 17:34
@dbanks12 dbanks12 requested a review from fcarreiro as a code owner February 18, 2025 17:34
@dbanks12 dbanks12 changed the title chore: avm TS test cleanup and refactors chore: prep for switching AVM to checkpointed native trees - TS test cleanup and refactors Feb 18, 2025
@dbanks12 dbanks12 requested a review from sirasistant February 18, 2025 19:49
@@ -58,9 +40,10 @@ describe('AVM WitGen & Circuit – check circuit', () => {
},
TIMEOUT,
);
// FIXME(dbanks12): fails with "Lookup PERM_MAIN_ALU failed."
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was accidentally removed in a previous PR

std::hash::sha256(data)
sha256::sha256_var(data, data.len() as u64)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created this fn last week and used the old stdlib sha

Comment on lines -403 to -408
#[public]
fn assert_timestamp(expected_timestamp: u64) {
let timestamp = context.timestamp();
assert(timestamp == expected_timestamp, "timestamp does not match");
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment on lines 58 to 62
const tx = await mockTx(1234, {
numberOfNonRevertiblePublicCallRequests: 2,
numberOfRevertiblePublicCallRequests: 1,
});
tx.data.constants.historicalHeader = context.getBlockHeader(0);
tx.data.constants.vkTreeRoot = getVKTreeRoot();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed with @MirandaWood that this change should be okay

@@ -13,7 +13,6 @@ import { type PublicSideEffectTraceInterface } from '../public/side_effect_trace

export async function mockGetBytecode(worldStateDB: WorldStateDB, bytecode: Buffer) {
const commitment = await computePublicBytecodeCommitment(bytecode);
(worldStateDB as jest.Mocked<WorldStateDB>).getBytecode.mockResolvedValue(bytecode);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't used

Comment on lines -86 to -111

export function getAvmTestContractFunctionSelector(functionName: string): Promise<FunctionSelector> {
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
assert(!!artifact, `Function ${functionName} not found in AvmTestContractArtifact`);
const params = artifact.parameters;
return FunctionSelector.fromNameAndParameters(artifact.name, params);
}

export function getAvmTestContractArtifact(functionName: string): FunctionArtifact {
const artifact = AvmTestContractArtifact.functions.find(f => f.name === functionName)!;
assert(
!!artifact?.bytecode,
`No bytecode found for function ${functionName}. Try re-running bootstrap.sh on the repository root.`,
);
return artifact;
}

export function getAvmTestContractBytecode(functionName: string): Buffer {
const artifact = getAvmTestContractArtifact(functionName);
return artifact.bytecode;
}

export function getAvmTestContractPublicDispatchBytecode(): Buffer {
return getAvmTestContractBytecode(PUBLIC_DISPATCH_FN_NAME);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were duplicated from avm/fixtures

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Collaborator

@PhilWindle PhilWindle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine though I'm not familiar with most of the changes.

Copy link
Collaborator

@sirasistant sirasistant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVM related changes LGTM, only a small doubt regarding hrtime

@@ -132,6 +134,9 @@ export class PublicTxSimulator {
tx.filterRevertedLogs(tx.data.forPublic!.nonRevertibleAccumulatedData);
}

const endTime = process.hrtime.bigint();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the simulator package is going to be fully imported in a browser context (I don't think we have client/server separation in package.json entrypoints) so it's going to import this use of process. Maybe we are already polyfilling process?
We could just use performance.now like in the other tests, unless we need nanosecond precision

Copy link
Collaborator

@spalladino spalladino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I glossed over the avm_proving_tests I'm not familiar with, but the rest looks ok.

Side note: I didn't know about the PublicSimulationTester capabilities to create valid txs, it's a really nice building block for testing! We need to make these more widely available.

@dbanks12 dbanks12 enabled auto-merge (squash) February 19, 2025 16:51
@dbanks12 dbanks12 disabled auto-merge February 19, 2025 16:58
@dbanks12 dbanks12 enabled auto-merge (squash) February 19, 2025 20:01
@dbanks12 dbanks12 merged commit c1cc3ed into master Feb 19, 2025
13 checks passed
@dbanks12 dbanks12 deleted the db/testing-updates branch February 19, 2025 20:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants