Skip to content

Commit

Permalink
feat: new kernel interface, base rollup cbinds + tests (#115)
Browse files Browse the repository at this point in the history
* add basic contract deployment test for private kernel

* chore(base_rollup): scaffold

* feat(base_rollup): scaffold

* fix(base_rollup): var name changes

* feat(base_rollup): historical subtree membership checks

* feat(merge_rollup) merge rollup types

* clean(merge): clean types and scaffold

* refactor(merge): seperate merge and base rollup

* fix(base): rename messup

* clean(merge): pr review

* initial test setup

* fix: paths and prints

* deleted deps

* minor tweaks

* fix(merge|base): aggregation object naming issue

* fix: change interface of base rollup

* fix witness init

* fix(ts): update bindings (#108)

* refactor(merge): seperate merge and base rollup

* initial test setup

* fix(ts-bindings): reduce roots to calldatahash

* fix: remove prover id

* fix: base rollup pub inputs ts tests

* remove deps

* rm gtest

* fix: scuffed rebase

* fix: scuffed rebase cont.

* fix: update tests

---------

Co-authored-by: cheethas <[email protected]>
Co-authored-by: LHerskind <[email protected]>

* fix(ts): update incorrect constant parity

* minor fixes

* fix(base): update vk pointer handling (#111)

* fix: bb update

* fix: update head

* fix:(base): remove subtrees from interface (#110)

* update inputs and outputs of base per new miro dg

* update types and bindings

* fix ts bindings for base

* update kernel interfaces with sim

* fix new kernel interface

* fix circuit cbind

* Adding tests for base rollup + sha256 (#114)

* tests: tiny tests added

* fix: insert zero-leaf in contract + use sha256 + change calldata hash -> 2 fields

* fix: run tests in ci + remove log

* fix: fix tests

* fix: fix comments

* fix: better comment

* private kernel test doing actual proving

* feat(base): insert commitments and contracts into end trees (#116)

* insert commitments and contracts into end trees

* fix merkle membership refactoring

* add new root to snapshot

* fix per pr comments

* update ts constants

* fix per pr comments

* fixing base rollup test

* fix: Update rollup sha256 input + add test with "meaningful" input (#118)

* base test cbind fixed

* remove old comment

* add cbind tests to base rollup

* fix unintentional changes

* cbind tests for base rollup with some commented out checks

---------

Co-authored-by: cheethas <[email protected]>
Co-authored-by: LHerskind <[email protected]>
Co-authored-by: Maddiaa <[email protected]>
Co-authored-by: Rahul Kothari <[email protected]>
Co-authored-by: Lasse Herskind <[email protected]>
  • Loading branch information
6 people authored Mar 29, 2023
1 parent 6c55c5c commit 8b36f95
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 244 deletions.
188 changes: 15 additions & 173 deletions cpp/src/aztec3/circuits/kernel/private/.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,167 +637,7 @@ TEST(private_kernel_tests, test_basic_contract_deployment)
info("n: ", private_kernel_composer.num_gates);
}

TEST(private_kernel_tests, test_create_proof_cbind_circuit)
{
//***************************************************************************
// Some private CIRCUIT proof (`constructor`, in this case)
// and the cbind to generate it
//***************************************************************************

const NT::address new_contract_address = 12345;
// const NT::fr new_contract_leaf_index = 1;
const NT::fr new_portal_contract_address = 23456;

const NT::fr msg_sender_private_key = 123456789;
const NT::address msg_sender =
NT::fr(uint256_t(0x01071e9a23e0f7edULL, 0x5d77b35d1830fa3eULL, 0xc6ba3660bb1f0c0bULL, 0x2ef9f7f09867fd6eULL));
const NT::address tx_origin = msg_sender;

Composer constructor_composer = Composer("../barretenberg/cpp/srs_db/ignition");
DB db;

FunctionData<NT> function_data{
.function_selector = 1, // TODO: deduce this from the contract, somehow.
.is_private = true,
.is_constructor = true,
};

CallContext<NT> call_context{
.msg_sender = msg_sender,
.storage_contract_address = new_contract_address,
.tx_origin = msg_sender,
.is_delegate_call = false,
.is_static_call = false,
.is_contract_deployment = true,
};

NativeOracle constructor_oracle =
NativeOracle(db, new_contract_address, function_data, call_context, msg_sender_private_key);
OracleWrapper constructor_oracle_wrapper = OracleWrapper(constructor_composer, constructor_oracle);

FunctionExecutionContext constructor_ctx(constructor_composer, constructor_oracle_wrapper);

auto arg0 = NT::fr(5);
auto arg1 = NT::fr(1);
auto arg2 = NT::fr(999);

OptionalPrivateCircuitPublicInputs<NT> opt_constructor_public_inputs =
constructor(constructor_ctx, arg0, arg1, arg2);

ContractDeploymentData<NT> contract_deployment_data{
.constructor_vk_hash = 0, // TODO actually get this?
.function_tree_root = 0, // TODO actually get this?
.contract_address_salt = 42,
.portal_contract_address = new_portal_contract_address,
};
opt_constructor_public_inputs.contract_deployment_data = contract_deployment_data;

PrivateCircuitPublicInputs<NT> constructor_public_inputs = opt_constructor_public_inputs.remove_optionality();

Prover constructor_prover = constructor_composer.create_prover();
NT::Proof constructor_proof = constructor_prover.construct_proof();
// info("\nconstructor_proof: ", constructor_proof.proof_data);

std::shared_ptr<NT::VK> constructor_vk = constructor_composer.compute_verification_key();

//***************************************************************************
// We can create a TxRequest from some of the above data. Users must sign a TxRequest in order to give permission
// for a tx to take place - creating a SignedTxRequest.
//***************************************************************************

TxRequest<NT> constructor_tx_request = TxRequest<NT>{
.from = tx_origin,
.to = new_contract_address,
.function_data = function_data,
.args = constructor_public_inputs.args,
.nonce = 0,
.tx_context =
TxContext<NT>{
.is_fee_payment_tx = false,
.is_rebate_payment_tx = false,
.is_contract_deployment_tx = false,
.contract_deployment_data = contract_deployment_data,
},
.chain_id = 1,
};

SignedTxRequest<NT> signed_constructor_tx_request = SignedTxRequest<NT>{
.tx_request = constructor_tx_request,

// .signature = TODO: need a method for signing a TxRequest.
};

//***************************************************************************
// We mock a kernel circuit proof for the base case of kernel recursion (because even the first iteration of the
// kernel circuit expects to verify some previous kernel circuit).
//***************************************************************************

Composer mock_kernel_composer = Composer("../barretenberg/cpp/srs_db/ignition");

// TODO: we have a choice to make:
// Either the `end` state of the mock kernel's public inputs can be set equal to the public call we _want_ to
// verify in the first round of recursion, OR, we have some fiddly conditional logic in the circuit to ignore
// certain checks if we're handling the 'base case' of the recursion.
// I've chosen the former, for now.
const CallStackItem<NT, CallType::Private> constructor_call_stack_item{
.contract_address = constructor_tx_request.to,

.function_data = constructor_tx_request.function_data,

.public_inputs = constructor_public_inputs,
};

std::array<NT::fr, KERNEL_PRIVATE_CALL_STACK_LENGTH> initial_kernel_private_call_stack{};
initial_kernel_private_call_stack[0] = constructor_call_stack_item.hash();

uint8_t const* pk_buf;
size_t pk_size = private_kernel__init_proving_key(&pk_buf);
info("Proving key size: ", pk_size);

uint8_t const* vk_buf;
size_t vk_size = private_kernel__init_verification_key(pk_buf, &vk_buf);
info("Verification key size: ", vk_size);

std::vector<uint8_t> signed_constructor_tx_request_vec;
write(signed_constructor_tx_request_vec, signed_constructor_tx_request);

PrivateCallData<NT> private_constructor_call = PrivateCallData<NT>{
.call_stack_item = constructor_call_stack_item,
.private_call_stack_preimages = constructor_ctx.get_private_call_stack_items(),

.proof = constructor_proof,
.vk = constructor_vk,

// .function_leaf_membership_witness TODO
// .contract_leaf_membership_witness TODO

.portal_contract_address = new_portal_contract_address,
};
std::vector<uint8_t> private_constructor_call_vec;
write(private_constructor_call_vec, private_constructor_call);

uint8_t const* proof_data;
size_t proof_data_size;
uint8_t const* public_inputs;
info("creating proof");
size_t public_inputs_size = private_kernel__create_proof(signed_constructor_tx_request_vec.data(),
pk_buf,
private_constructor_call_vec.data(),
pk_buf,
false, // proverless
&proof_data,
&proof_data_size,
&public_inputs);
info("Proof size: ", proof_data_size);
info("PublicInputs size: ", public_inputs_size);

free((void*)pk_buf);
free((void*)vk_buf);
free((void*)proof_data);
free((void*)public_inputs);
}

TEST(private_kernel_tests, test_create_proof_cbind_native)
TEST(private_kernel_tests, test_create_proof_cbinds)
{
//***************************************************************************
// Some private NATIVE mocked proof (`constructor`, in this case)
Expand Down Expand Up @@ -937,17 +777,21 @@ TEST(private_kernel_tests, test_create_proof_cbind_native)
write(private_constructor_call_vec, private_constructor_call);

uint8_t const* proof_data;
size_t proof_data_size;
uint8_t const* public_inputs;
info("creating proof");
size_t public_inputs_size = private_kernel__create_proof(signed_constructor_tx_request_vec.data(),
pk_buf,
private_constructor_call_vec.data(),
pk_buf,
true, // proverless
&proof_data,
&proof_data_size,
&public_inputs);
info("Simulating to generate public inputs...");
size_t public_inputs_size = private_kernel__sim(signed_constructor_tx_request_vec.data(),
nullptr, // no previous kernel on first iteration
private_constructor_call_vec.data(),
true, // first iteration
&public_inputs);

info("Proving");
size_t proof_data_size = private_kernel__prove(signed_constructor_tx_request_vec.data(),
nullptr,
private_constructor_call_vec.data(),
pk_buf,
true, // first iteration
&proof_data);
info("Proof size: ", proof_data_size);
info("PublicInputs size: ", public_inputs_size);

Expand All @@ -957,6 +801,4 @@ TEST(private_kernel_tests, test_create_proof_cbind_native)
free((void*)public_inputs);
}



} // namespace aztec3::circuits::kernel::private_kernel
Loading

0 comments on commit 8b36f95

Please sign in to comment.