Skip to content

feat(noir-libs): unify Private and Public Context Apis #1484

@Maddiaa0

Description

@Maddiaa0

See #1358 for more information

Currently public functions have no context object, which leads them to have completely different code paths to the private counter part, even if the goal of the function is the same.

Currently a private function looks as follows:

    fn transfer(
        //*********************************/
        // Should eventually be hidden:
        inputs: PrivateContextInputs,
        //*********************************/
        amount: u120, 
        sender: Field, 
        recipient: Field,
    ) -> distinct pub abi::PrivateCircuitPublicInputs {
        let mut context = Context::new(inputs, abi::hash_args([amount as Field, sender, recipient]));

As a reminder, here's that struct:

struct PrivateContextInputs {
    call_context : CallContext,
    roots: CommitmentTreesRoots,

    contract_deployment_data: ContractDeploymentData,

    private_global_variables: PrivateGlobalVariables,
}

While a public function looks like this:

    fn transfer(
        amount: u120, 
        sender: Field, 
        recipient: Field,
    )  {
       ...logic

However, there is also a PublicContextInputs struct:

struct PublicContextInputs {
    call_context: CallContext,
    block_data: ConstantHistoricBlockData,

    public_global_variables: PublicGlobalVariables,
}

That contains a call context object.

We should be able to call methods like context.this_address() and context.this_portal_address() with the same syntax in Private and Public contexts.

Note: these contexts will eventually be hidden from the developer, they will be wrapped in macros / handled at the compiler level

Metadata

Metadata

Assignees

Labels

A-ux/devexArea: relates to external ux / devex. (Users typically are devs) (See also A-internal-devex)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions