-
Notifications
You must be signed in to change notification settings - Fork 178
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
fix: unencryptedlogs witgen #8669
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1831,15 +1831,14 @@ TEST_F(AvmExecutionTests, ExecutorThrowsWithIncorrectNumberOfPublicInputs) | |
TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) | ||
{ | ||
// Set values into the first register to emit | ||
std::string bytecode_hex = to_hex(OpCode::SET_8) + // opcode Set | ||
"00" // Indirect flag | ||
+ to_hex(AvmMemoryTag::U32) + | ||
"01" // value 1 | ||
"01" // dst_offset 1 | ||
// Cast set to field | ||
+ to_hex(OpCode::CAST_8) + // opcode CAST | ||
"00" // Indirect flag | ||
+ to_hex(AvmMemoryTag::FF) + | ||
std::string bytecode_hex = to_hex(OpCode::SET_8) + // opcode Set | ||
"00" // Indirect flag | ||
+ to_hex(AvmMemoryTag::U32) + // tag U32 | ||
"01" // value 1 | ||
"01" // dst_offset 1 | ||
+ to_hex(OpCode::CAST_8) + // opcode CAST (to field) | ||
"00" // Indirect flag | ||
+ to_hex(AvmMemoryTag::FF) + // tag FF | ||
"01" // dst 1 | ||
"01" // dst 1 | ||
+ to_hex(OpCode::EMITNOTEHASH) + // opcode EMITNOTEHASH | ||
|
@@ -1902,13 +1901,15 @@ TEST_F(AvmExecutionTests, kernelOutputEmitOpcodes) | |
// CHECK EMIT UNENCRYPTED LOG | ||
auto emit_log_row = | ||
std::ranges::find_if(trace.begin(), trace.end(), [](Row r) { return r.main_sel_op_emit_unencrypted_log == 1; }); | ||
EXPECT_EQ(emit_log_row->main_ia, 1); | ||
// Trust me bro for now, this is the truncated sha output | ||
FF expected_hash = FF(std::string("0x006db65fd59fd356f6729140571b5bcd6bb3b83492a16e1bf0a3884442fc3c8a")); | ||
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. Now that witgen calculates the truncated sha256 hash of the logs, we need to do the same - I promise this is the real hash |
||
EXPECT_EQ(emit_log_row->main_ia, expected_hash); | ||
EXPECT_EQ(emit_log_row->main_side_effect_counter, 2); | ||
|
||
uint32_t emit_log_out_offset = START_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET; | ||
auto emit_log_kernel_out_row = | ||
std::ranges::find_if(trace.begin(), trace.end(), [&](Row r) { return r.main_clk == emit_log_out_offset; }); | ||
EXPECT_EQ(emit_log_kernel_out_row->main_kernel_value_out, 1); | ||
EXPECT_EQ(emit_log_kernel_out_row->main_kernel_value_out, expected_hash); | ||
EXPECT_EQ(emit_log_kernel_out_row->main_kernel_side_effect_out, 2); | ||
feed_output(emit_log_out_offset, 1, 2, 0); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,8 @@ class AvmKernelTraceBuilder { | |
std::unordered_map<uint32_t, uint32_t> kernel_output_selector_counter; | ||
|
||
AvmKernelTraceBuilder(uint32_t initial_side_effect_counter, VmPublicInputs public_inputs, ExecutionHints hints) | ||
: initial_side_effect_counter(initial_side_effect_counter) | ||
, public_inputs(std::move(public_inputs)) | ||
: public_inputs(std::move(public_inputs)) | ||
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. Had to re-order this because public_inputs is now |
||
, initial_side_effect_counter(initial_side_effect_counter) | ||
, hints(std::move(hints)) | ||
{} | ||
|
||
|
@@ -92,14 +92,16 @@ class AvmKernelTraceBuilder { | |
void op_nullifier_exists(uint32_t clk, uint32_t side_effect_counter, const FF& nullifier, uint32_t result); | ||
void op_emit_nullifier(uint32_t clk, uint32_t side_effect_counter, const FF& nullifier); | ||
void op_l1_to_l2_msg_exists(uint32_t clk, uint32_t side_effect_counter, const FF& message, uint32_t result); | ||
void op_emit_unencrypted_log(uint32_t clk, uint32_t side_effect_counter, const FF& log_hash); | ||
void op_emit_unencrypted_log(uint32_t clk, uint32_t side_effect_counter, const FF& log_hash, const FF& log_length); | ||
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. emit_unencrypted_log actually has metadata, but we weren't properly handling |
||
void op_emit_l2_to_l1_msg(uint32_t clk, uint32_t side_effect_counter, const FF& l2_to_l1_msg, const FF& recipient); | ||
|
||
// This is temporarily made public so we can access PIs | ||
VmPublicInputs public_inputs; | ||
|
||
private: | ||
std::vector<KernelTraceEntry> kernel_trace; | ||
|
||
uint32_t initial_side_effect_counter; | ||
VmPublicInputs public_inputs; | ||
ExecutionHints hints; | ||
|
||
// Output index counters | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,11 +183,7 @@ export class PublicSideEffectTrace implements PublicSideEffectTraceInterface { | |
const basicLogHash = Fr.fromBuffer(ulog.hash()); | ||
this.unencryptedLogs.push(ulog); | ||
this.allUnencryptedLogs.push(ulog); | ||
// We want the length of the buffer output from function_l2_logs -> toBuffer to equal the stored log length in the kernels. | ||
// The kernels store the length of the processed log as 4 bytes; thus for this length value to match the log length stored in the kernels, | ||
// we need to add four to the length here. | ||
// https://github.com/AztecProtocol/aztec-packages/issues/6578#issuecomment-2125003435 | ||
this.unencryptedLogsHashes.push(new LogHash(basicLogHash, this.sideEffectCounter, new Fr(ulog.length + 4))); | ||
this.unencryptedLogsHashes.push(new LogHash(basicLogHash, this.sideEffectCounter, new Fr(ulog.length))); | ||
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. the +4 is actually already handled in the |
||
this.logger.debug(`NEW_UNENCRYPTED_LOG cnt: ${this.sideEffectCounter}`); | ||
this.incrementSideEffectCounter(); | ||
} | ||
|
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.
This is just some formatting