Skip to content

Commit

Permalink
refactor: Use context instead of custom oracles for public functions (#…
Browse files Browse the repository at this point in the history
…1754)

Fixes #1753, #1755 and use context for nullifiers and commitments in
public.
  • Loading branch information
LHerskind authored Aug 23, 2023
1 parent ad1c2cb commit 46de77a
Show file tree
Hide file tree
Showing 16 changed files with 3,802 additions and 3,859 deletions.
3 changes: 0 additions & 3 deletions yarn-project/acir-simulator/src/acvm/acvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ type ORACLE_NAMES =
| 'enqueuePublicFunctionCall'
| 'storageRead'
| 'storageWrite'
| 'createCommitment'
| 'createL2ToL1Message'
| 'createNullifier'
| 'getCommitment'
| 'getL1ToL2Message'
| 'getPortalContractAddress'
Expand Down
29 changes: 10 additions & 19 deletions yarn-project/acir-simulator/src/public/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export class PublicExecutor {

const initialWitness = getInitialWitness(execution.args, execution.callContext, this.blockData, globalVariables);
const storageActions = new ContractStorageActionsCollector(this.stateDb, execution.contractAddress);
const newCommitments: Fr[] = [];
const newL2ToL1Messages: Fr[] = [];
const newNullifiers: Fr[] = [];
const nestedExecutions: PublicExecutionResult[] = [];
const unencryptedLogs = new FunctionL2Logs([]);
// Functions can request to pack arguments before calling other functions.
Expand Down Expand Up @@ -116,21 +113,6 @@ export class PublicExecutor {
}
return newValues.map(v => toACVMField(v));
},
createCommitment: async ([commitment]) => {
this.log('Creating commitment: ' + commitment.toString());
newCommitments.push(fromACVMField(commitment));
return await Promise.resolve(ZERO_ACVM_FIELD);
},
createL2ToL1Message: async ([message]) => {
this.log('Creating L2 to L1 message: ' + message.toString());
newL2ToL1Messages.push(fromACVMField(message));
return await Promise.resolve(ZERO_ACVM_FIELD);
},
createNullifier: async ([nullifier]) => {
this.log('Creating nullifier: ' + nullifier.toString());
newNullifiers.push(fromACVMField(nullifier));
return await Promise.resolve(ZERO_ACVM_FIELD);
},
callPublicFunction: async ([address], [functionSelector], [argsHash]) => {
const args = packedArgs.unpack(fromACVMField(argsHash));
this.log(`Public function call: addr=${address} selector=${functionSelector} args=${args.join(',')}`);
Expand Down Expand Up @@ -161,7 +143,16 @@ export class PublicExecutor {
},
});

const { returnValues } = extractPublicCircuitPublicInputs(partialWitness, acir);
const {
returnValues,
newL2ToL1Msgs,
newCommitments: newCommitmentsPadded,
newNullifiers: newNullifiersPadded,
} = extractPublicCircuitPublicInputs(partialWitness, acir);

const newL2ToL1Messages = newL2ToL1Msgs.filter(v => !v.isZero());
const newCommitments = newCommitmentsPadded.filter(v => !v.isZero());
const newNullifiers = newNullifiersPadded.filter(v => !v.isZero());

const [contractStorageReads, contractStorageUpdateRequests] = storageActions.collect();
this.log(
Expand Down
Loading

0 comments on commit 46de77a

Please sign in to comment.