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

test(avm): Add a TS prover test suite for each avm context function #6957

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions noir-projects/aztec-nr/aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ impl PublicContext {
* @param event_selector The event selector for the log.
* @param message The message to emit in the log.
*/
pub fn emit_unencrypted_log_with_selector<T,N>(
pub fn emit_unencrypted_log_with_selector<T, N>(
&mut self,
event_selector: Field,
log: T
) where T: Serialize<N> {
emit_unencrypted_log(event_selector, Serialize::serialize(log).as_slice());
}
// For compatibility with the selector-less API. We'll probably rename the above one.
pub fn emit_unencrypted_log<T,N>(&mut self, log: T) where T: Serialize<N> {
pub fn emit_unencrypted_log<T, N>(&mut self, log: T) where T: Serialize<N> {
self.emit_unencrypted_log_with_selector(/*event_selector=*/ 5, log);
}
pub fn note_hash_exists(self, note_hash: Field, leaf_index: Field) -> bool {
Expand Down Expand Up @@ -169,6 +169,12 @@ impl PublicContext {
fn get_args_hash(self) -> Field {
self.inputs.args_hash
}
fn l2_gas_left(self) -> Field {
l2_gas_left()
}
fn da_gas_left(self) -> Field {
da_gas_left()
}
}

// Helper functions
Expand Down Expand Up @@ -368,4 +374,4 @@ impl<N> FunctionReturns<N> {
pub fn deserialize_into<T>(self) -> T where T: Deserialize<N> {
Deserialize::deserialize(self.raw())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ contract AvmTest {
context.timestamp()
}

#[aztec(public)]
fn get_l2_gas_left() -> Field {
context.l2_gas_left()
}

#[aztec(public)]
fn get_da_gas_left() -> Field {
context.da_gas_left()
}

// #[aztec(public)]
// fn get_contract_call_depth() -> Field {
// context.contract_call_depth()
Expand Down
45 changes: 45 additions & 0 deletions yarn-project/bb-prover/src/avm_proving.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,51 @@ describe('AVM WitGen, proof generation and verification', () => {
// )
});

it.skip(
'Should prove a keccak hash evaluation',
async () => {
await proveAndVerifyAvmTestContract('keccak_hash', [
new Fr(0),
new Fr(1),
new Fr(2),
new Fr(3),
new Fr(4),
new Fr(5),
new Fr(6),
new Fr(7),
new Fr(8),
new Fr(9),
]);
},
TIMEOUT,
);

/************************************************************************
* AvmContext functions
************************************************************************/
const avmContextFunctions = [
'get_address',
'get_storage_address',
'get_sender',
'get_fee_per_l2_gas',
'get_fee_per_da_gas',
'get_transaction_fee',
'get_chain_id',
'get_version',
'get_block_number',
'get_timestamp',
'get_l2_gas_left',
'get_da_gas_left',
];

it.each(avmContextFunctions)(
'Should prove an avm context function %s',
async contextFunction => {
await proveAndVerifyAvmTestContract(contextFunction);
},
TIMEOUT,
);

const proveAndVerifyAvmTestContract = async (functionName: string, calldata: Fr[] = []) => {
const startSideEffectCounter = 0;
const environment = initExecutionEnvironment({ calldata });
Expand Down
Loading