Skip to content

Commit

Permalink
refactor: rename call_context.start_side_effect_counter
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Mar 11, 2024
1 parent ee9c44c commit 87c2bb7
Show file tree
Hide file tree
Showing 16 changed files with 4,321 additions and 84 deletions.
3,325 changes: 3,324 additions & 1 deletion boxes/boxes/react/src/contracts/target/boxreact-BoxReact.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl PrivateContext {
is_delegate_call
);

assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
assert_eq(item.public_inputs.call_context.enqueued_side_effect_counter, self.side_effect_counter);
self.side_effect_counter = item.public_inputs.end_side_effect_counter + 1;

assert(contract_address.eq(item.contract_address));
Expand Down Expand Up @@ -476,7 +476,7 @@ impl PrivateContext {
assert(contract_address.eq(item.contract_address));
assert(function_selector.eq(item.function_data.selector));

assert_eq(item.public_inputs.call_context.start_side_effect_counter, self.side_effect_counter);
assert_eq(item.public_inputs.call_context.enqueued_side_effect_counter, self.side_effect_counter);
// We increment the sideffect counter by one, to account for the call itself being a side effect.
self.side_effect_counter = self.side_effect_counter + 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
abis::function_selector::FunctionSelector, address::{EthAddress, AztecAddress},
constants::{CALL_CONTEXT_LENGTH, GENERATOR_INDEX__CALL_CONTEXT}, hash::pedersen_hash,
traits::{Deserialize, Hash, Serialize}
traits::{Deserialize, Hash, Serialize}, abis::side_effect::Ordered
};

// docs:start:call-context
Expand All @@ -16,7 +16,7 @@ struct CallContext {
is_static_call : bool,
is_contract_deployment : bool,

start_side_effect_counter : u32,
enqueued_side_effect_counter : u32,
}
// docs:end:call-context

Expand All @@ -30,7 +30,13 @@ impl CallContext {
assert(self.is_delegate_call == false);
assert(self.is_static_call == false);
assert(self.is_contract_deployment == false);
assert(self.start_side_effect_counter == 0);
assert(self.enqueued_side_effect_counter == 0);
}
}

impl Ordered for CallContext {
fn counter(self) -> u32 {
self.enqueued_side_effect_counter
}
}

Expand All @@ -44,7 +50,7 @@ impl Eq for CallContext {
& (call_context.is_delegate_call == self.is_delegate_call)
& (call_context.is_static_call == self.is_static_call)
& (call_context.is_contract_deployment == self.is_contract_deployment)
& (call_context.start_side_effect_counter == self.start_side_effect_counter)
& (call_context.enqueued_side_effect_counter == self.enqueued_side_effect_counter)
}
}

Expand All @@ -64,7 +70,7 @@ impl Serialize<CALL_CONTEXT_LENGTH> for CallContext {
self.is_delegate_call as Field,
self.is_static_call as Field,
self.is_contract_deployment as Field,
self.start_side_effect_counter as Field,
self.enqueued_side_effect_counter as Field,
]
}
}
Expand All @@ -79,7 +85,7 @@ impl Deserialize<CALL_CONTEXT_LENGTH> for CallContext {
is_delegate_call: serialized[4] as bool,
is_static_call: serialized[5] as bool,
is_contract_deployment: serialized[6] as bool,
start_side_effect_counter: serialized[7] as u32,
enqueued_side_effect_counter: serialized[7] as u32,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl PrivateCircuitPublicInputsBuilder {
is_delegate_call: false,
is_static_call: false,
is_contract_deployment: is_constructor,
start_side_effect_counter: 0
enqueued_side_effect_counter: 0
};
public_inputs.call_context = call_context;
public_inputs.args_hash = args_hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl PublicCallDataBuilder {
is_delegate_call: false,
is_static_call: false,
is_contract_deployment: false,
start_side_effect_counter: 0, // needed?
enqueued_side_effect_counter: 0, // needed?
};

PublicCallDataBuilder {
Expand Down
1,000 changes: 954 additions & 46 deletions yarn-project/circuits.js/fixtures/Benchmarking.test.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions yarn-project/circuits.js/src/structs/call_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CallContext {
/**
* The start side effect counter for this call context.
*/
public startSideEffectCounter: number,
public enqueuedSideEffectCounter: number,
) {}

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ export class CallContext {
fields.isDelegateCall,
fields.isStaticCall,
fields.isContractDeployment,
fields.startSideEffectCounter,
fields.enqueuedSideEffectCounter,
] as const;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ export class CallContext {
callContext.isDelegateCall === this.isDelegateCall &&
callContext.isStaticCall === this.isStaticCall &&
callContext.isContractDeployment === this.isContractDeployment &&
callContext.startSideEffectCounter === this.startSideEffectCounter
callContext.enqueuedSideEffectCounter === this.enqueuedSideEffectCounter
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class PrivateCallStackItem {
this.hash(),
parentCallContext.storageContractAddress,
callerContext,
new Fr(this.publicInputs.callContext.startSideEffectCounter),
new Fr(this.publicInputs.callContext.enqueuedSideEffectCounter),
this.publicInputs.endSideEffectCounter,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class PublicCallRequest {
item.hash(),
this.parentCallContext.storageContractAddress,
callerContext,
new Fr(this.callContext.startSideEffectCounter),
new Fr(this.callContext.enqueuedSideEffectCounter),
Fr.ZERO,
);
}
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ export function makePublicCallRequest(seed = 1): PublicCallRequest {
isStaticCall: false,
isDelegateCall: false,
isContractDeployment: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});
return new PublicCallRequest(
makeAztecAddress(seed),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export function mapCallContextFromNoir(callContext: CallContextNoir): CallContex
callContext.is_delegate_call,
callContext.is_static_call,
callContext.is_contract_deployment,
mapNumberFromNoir(callContext.start_side_effect_counter),
mapNumberFromNoir(callContext.enqueued_side_effect_counter),
);
}

Expand All @@ -486,7 +486,7 @@ export function mapCallContextToNoir(callContext: CallContext): CallContextNoir
is_delegate_call: callContext.isDelegateCall,
is_static_call: callContext.isStaticCall,
is_contract_deployment: callContext.isContractDeployment,
start_side_effect_counter: mapNumberToNoir(callContext.startSideEffectCounter),
enqueued_side_effect_counter: mapNumberToNoir(callContext.enqueuedSideEffectCounter),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ describe('public_processor', () => {
baseContractAddressSeed,
baseContractAddressSeed,
].map(makePublicCallRequest);
callRequests[0].callContext.startSideEffectCounter = 2;
callRequests[1].callContext.startSideEffectCounter = 3;
callRequests[2].callContext.startSideEffectCounter = 4;
callRequests[0].callContext.enqueuedSideEffectCounter = 2;
callRequests[1].callContext.enqueuedSideEffectCounter = 3;
callRequests[2].callContext.enqueuedSideEffectCounter = 4;

const kernelOutput = makePrivateKernelTailCircuitPublicInputs(0x10);
kernelOutput.end.unencryptedLogsHash = [Fr.ZERO, Fr.ZERO];
Expand Down Expand Up @@ -417,9 +417,9 @@ describe('public_processor', () => {
baseContractAddressSeed,
baseContractAddressSeed,
].map(makePublicCallRequest);
callRequests[0].callContext.startSideEffectCounter = 2;
callRequests[1].callContext.startSideEffectCounter = 3;
callRequests[2].callContext.startSideEffectCounter = 4;
callRequests[0].callContext.enqueuedSideEffectCounter = 2;
callRequests[1].callContext.enqueuedSideEffectCounter = 3;
callRequests[2].callContext.enqueuedSideEffectCounter = 4;

const kernelOutput = makePrivateKernelTailCircuitPublicInputs(0x10);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/simulator/src/client/execution_result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ export function collectEnqueuedPublicFunctionCalls(execResult: ExecutionResult):
return [
...execResult.enqueuedPublicFunctionCalls,
...[...execResult.nestedExecutions].flatMap(collectEnqueuedPublicFunctionCalls),
].sort((a, b) => b.callContext.startSideEffectCounter - a.callContext.startSideEffectCounter);
].sort((a, b) => b.callContext.enqueuedSideEffectCounter - a.callContext.enqueuedSideEffectCounter);
}
4 changes: 2 additions & 2 deletions yarn-project/simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ describe('Private Execution test suite', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 1,
enqueuedSideEffectCounter: 1,
}),
parentCallContext: CallContext.from({
msgSender: parentAddress,
Expand All @@ -841,7 +841,7 @@ describe('Private Execution test suite', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 1,
enqueuedSideEffectCounter: 1,
}),
});

Expand Down
18 changes: 9 additions & 9 deletions yarn-project/simulator/src/public/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

publicContracts.getBytecode.mockResolvedValue(Buffer.from(mintArtifact.bytecode, 'base64'));
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

recipientStorageSlot = computeSlotForMapping(new Fr(6n), recipient);
Expand Down Expand Up @@ -275,7 +275,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

// eslint-disable-next-line require-await
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

publicContracts.getBytecode.mockResolvedValue(Buffer.from(shieldArtifact.bytecode, 'base64'));
Expand Down Expand Up @@ -390,7 +390,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

publicContracts.getBytecode.mockResolvedValue(Buffer.from(createL2ToL1MessagePublicArtifact.bytecode, 'base64'));
Expand Down Expand Up @@ -421,7 +421,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

publicContracts.getBytecode.mockResolvedValue(Buffer.from(createNullifierPublicArtifact.bytecode, 'base64'));
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});

const computeGlobalVariables = () =>
Expand Down Expand Up @@ -680,7 +680,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});
assertGlobalVarsArtifact = TestContractArtifact.functions.find(f => f.name === 'assert_public_global_vars')!;
functionData = FunctionData.fromAbi(assertGlobalVarsArtifact);
Expand Down Expand Up @@ -764,7 +764,7 @@ describe('ACIR public execution simulator', () => {
isContractDeployment: false,
isDelegateCall: false,
isStaticCall: false,
startSideEffectCounter: 0,
enqueuedSideEffectCounter: 0,
});
assertHeaderPublicArtifact = TestContractArtifact.functions.find(f => f.name === 'assert_header_public')!;
functionData = FunctionData.fromAbi(assertHeaderPublicArtifact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class PublicExecutionContext extends TypedOracle {
isDelegateCall,
isStaticCall,
// TODO (alexg) move this to noir
startSideEffectCounter: this.sideEffectCounter.count(),
enqueuedSideEffectCounter: this.sideEffectCounter.count(),
});

const nestedExecution: PublicExecution = {
Expand Down

0 comments on commit 87c2bb7

Please sign in to comment.