-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(avm): avm circuit actually uses public inputs columns passed from TS #6819
Merged
dbanks12
merged 1 commit into
db/avm-execution-hints-ts
from
db/avm-use-public-inputs-from-ts
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,8 @@ namespace bb::avm_trace { | |
std::vector<FF> Execution::getDefaultPublicInputs() | ||
{ | ||
std::vector<FF> public_inputs_vec(PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH); | ||
public_inputs_vec.at(DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = 1000000000; | ||
public_inputs_vec.at(L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET) = 1000000000; | ||
public_inputs_vec.at(DA_START_GAS_LEFT_PCPI_OFFSET) = 1000000000; | ||
public_inputs_vec.at(L2_START_GAS_LEFT_PCPI_OFFSET) = 1000000000; | ||
return public_inputs_vec; | ||
} | ||
|
||
|
@@ -47,18 +47,28 @@ std::vector<FF> Execution::getDefaultPublicInputs() | |
* @return The verifier key and zk proof of the execution. | ||
*/ | ||
std::tuple<AvmFlavor::VerificationKey, HonkProof> Execution::prove(std::vector<uint8_t> const& bytecode, | ||
std::vector<FF> const& calldata) | ||
std::vector<FF> const& calldata, | ||
std::vector<FF> const& public_inputs_vec) | ||
{ | ||
if (public_inputs_vec.size() != PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH) { | ||
throw_or_abort("Public inputs vector is not of PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH"); | ||
} | ||
|
||
auto instructions = Deserialization::parse(bytecode); | ||
std::vector<FF> returndata{}; | ||
auto trace = gen_trace(instructions, returndata, calldata, getDefaultPublicInputs()); | ||
auto trace = gen_trace(instructions, returndata, calldata, public_inputs_vec); | ||
auto circuit_builder = bb::AvmCircuitBuilder(); | ||
circuit_builder.set_trace(std::move(trace)); | ||
|
||
auto composer = AvmComposer(); | ||
auto prover = composer.create_prover(circuit_builder); | ||
auto verifier = composer.create_verifier(circuit_builder); | ||
auto proof = prover.construct_proof(); | ||
|
||
// The proof starts with the serialized public inputs | ||
HonkProof proof(public_inputs_vec); | ||
auto raw_proof = prover.construct_proof(); | ||
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with keeping the order, but I'd switch the types:
|
||
// append the raw proof after the public inputs | ||
proof.insert(proof.end(), raw_proof.begin(), raw_proof.end()); | ||
// TODO(#4887): Might need to return PCS vk when full verify is supported | ||
return std::make_tuple(*verifier.key, proof); | ||
} | ||
|
@@ -108,8 +118,8 @@ VmPublicInputs Execution::convert_public_inputs(std::vector<FF> const& public_in | |
// Transaction fee | ||
kernel_inputs[TRANSACTION_FEE_SELECTOR] = public_inputs_vec[TRANSACTION_FEE_OFFSET]; | ||
|
||
kernel_inputs[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET]; | ||
kernel_inputs[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET]; | ||
kernel_inputs[DA_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[DA_START_GAS_LEFT_PCPI_OFFSET]; | ||
kernel_inputs[L2_GAS_LEFT_CONTEXT_INPUTS_OFFSET] = public_inputs_vec[L2_START_GAS_LEFT_PCPI_OFFSET]; | ||
|
||
return public_inputs; | ||
} | ||
|
@@ -124,10 +134,15 @@ bool Execution::verify(AvmFlavor::VerificationKey vk, HonkProof const& proof) | |
// crs_factory_); | ||
// output_state.pcs_verification_key = std::move(pcs_verification_key); | ||
|
||
// TODO: We hardcode public inputs for now | ||
VmPublicInputs public_inputs = convert_public_inputs(getDefaultPublicInputs()); | ||
std::vector<std::vector<FF>> public_inputs_vec = copy_public_inputs_columns(public_inputs); | ||
return verifier.verify_proof(proof, public_inputs_vec); | ||
std::vector<FF> public_inputs_vec; | ||
std::vector<FF> raw_proof; | ||
std::copy( | ||
proof.begin(), proof.begin() + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, std::back_inserter(public_inputs_vec)); | ||
std::copy(proof.begin() + PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH, proof.end(), std::back_inserter(raw_proof)); | ||
|
||
VmPublicInputs public_inputs = convert_public_inputs(public_inputs_vec); | ||
std::vector<std::vector<FF>> public_inputs_columns = copy_public_inputs_columns(public_inputs); | ||
return verifier.verify_proof(raw_proof, public_inputs_columns); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: if you have to modify this PR for some other reason, you could add the expected vs gotten sizes here.