Skip to content

Commit

Permalink
fix: use entrypoint instead of pay_init_fee
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Apr 9, 2024
1 parent ce3b85d commit 2a9efe2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
31 changes: 31 additions & 0 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ impl PrivateContext {
chain_id: self.inputs.private_global_variables.chain_id,
version: self.inputs.private_global_variables.version
};

// crate::oracle::debug_log::debug_log_format(
// "Finished private context with {0} note hash read requests",
// [self.note_hash_read_requests.len() as Field]
// );

priv_circuit_pub_inputs
}

Expand All @@ -199,6 +205,12 @@ impl PrivateContext {
}

pub fn push_note_hash_read_request(&mut self, note_hash: Field) {
// crate::oracle::debug_log::debug_log_format(
// "Pushing note hash read request for note_hash={0} counter={1} len={2}",
// [
// note_hash, self.side_effect_counter as Field, (self.note_hash_read_requests.len() as Field) + 1
// ]
// );
let side_effect = SideEffect { value: note_hash, counter: self.side_effect_counter };
self.note_hash_read_requests.push(side_effect);
self.side_effect_counter = self.side_effect_counter + 1;
Expand Down Expand Up @@ -343,6 +355,25 @@ impl PrivateContext {
is_delegate_call
);

let mut note_hash_read_req_count = 0;
for i in 0..MAX_NOTE_HASH_READ_REQUESTS_PER_CALL {
if !is_empty(item.public_inputs.note_hash_read_requests[i]) {
note_hash_read_req_count = note_hash_read_req_count + 1;
}
}

// crate::oracle::debug_log::debug_log_format(
// "Called private function got back contract_address={0} function_data={1} public_inputs={2} note_hash_read_reqs={3}",
// [
// item.contract_address.to_field(), item.function_data.hash(), item.public_inputs.hash(), note_hash_read_req_count
// ]
// );

// crate::oracle::debug_log::debug_log_array_with_prefix(
// "Called private function public inputs",
// item.public_inputs.serialize()
// );

assert_eq(item.public_inputs.call_context.side_effect_counter, self.side_effect_counter);
assert_eq(item.public_inputs.start_side_effect_counter, self.side_effect_counter);
self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ export class DeployAccountMethod extends DeployMethod {

if (options.fee && this.#feePaymentArtifact) {
const { address } = this.getInstance();
const emptyAppPayload = EntrypointPayload.fromAppExecution([]);
const feePayload = await EntrypointPayload.fromFeeOptions(options?.fee);

exec.calls.push({
to: address,
args: encodeArguments(this.#feePaymentArtifact, [feePayload]),
args: encodeArguments(this.#feePaymentArtifact, [emptyAppPayload, feePayload]),
functionData: FunctionData.fromAbi(this.#feePaymentArtifact),
});

exec.authWitnesses ??= [];
exec.packedArguments ??= [];

exec.authWitnesses.push(await this.#authWitnessProvider.createAuthWit(emptyAppPayload.hash()));
exec.authWitnesses.push(await this.#authWitnessProvider.createAuthWit(feePayload.hash()));
exec.packedArguments.push(...emptyAppPayload.packedArguments);
exec.packedArguments.push(...feePayload.packedArguments);

options.fee = undefined;
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/account_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class AccountManager {
this.accountContract.getContractArtifact(),
args,
'constructor',
'pay_init_fee',
'entrypoint',
);
}
return this.deployMethod;
Expand Down
10 changes: 10 additions & 0 deletions yarn-project/simulator/src/client/client_execution_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ export class ClientExecutionContext extends ViewDataOracle {

this.nestedExecutions.push(childExecutionResult);

const ci = childExecutionResult.callStackItem;
this.log(`Called private function and got back call stack item with hashes:
Contract address=${ci.contractAddress.toString()}
Function data=${ci.functionData.hash().toString()}
Public inputs=${ci.publicInputs.hash().toString()}
Count of note hash read requests=${ci.publicInputs.noteHashReadRequests.filter(x => !x.isEmpty()).length}
`);

// this.log(`Called private function public inputs: ${ci.publicInputs.toFields().map(f => f.toString())}`);

return childExecutionResult.callStackItem;
}

Expand Down

0 comments on commit 2a9efe2

Please sign in to comment.