Skip to content

Commit f2675fb

Browse files
committed
feat: L1 contract etherscan verification
1 parent 7534d82 commit f2675fb

File tree

105 files changed

+871
-1681
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+871
-1681
lines changed

barretenberg/cpp/pil/vm2/alu.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pol EXPECTED_C_TAG = (sel_op_add + sel_op_sub + sel_op_mul + sel_op_div + sel_op
119119
// Gating with (1 - sel_tag_err) is necessary because when an error occurs, we have to set the tag to 0,
120120
// which might not be equal to EXPECTED_C_TAG.
121121
#[C_TAG_CHECK]
122-
(1 - sel_err) * (EXPECTED_C_TAG - ic_tag) = 0;
122+
(1 - sel_tag_err) * (EXPECTED_C_TAG - ic_tag) = 0;
123123

124124
pol commit sel_tag_err;
125125
sel_tag_err * (1 - sel_tag_err) = 0;

barretenberg/cpp/pil/vm2/context.pil

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ namespace execution;
1212
#[skippable_if]
1313
sel = 0;
1414

15-
// TODO: make sure that all uses of `sel_error` here really should be "error" only
16-
// since `sel_error` will not be ` for the REVERT opcode. If we need "error or REVERT",
17-
// use `sel_failure`.
18-
1915
// Guaranteed to be boolean because sel_execute_call & sel_execute_static_call are mutually exclusive
2016
pol commit sel_enter_call;
2117
// The following selectors will be 0 if there is an error during execution (before the opcode execution step).
@@ -37,9 +33,7 @@ namespace execution;
3733
pol commit contract_address;
3834
pol commit bytecode_id;
3935
pol commit transaction_fee;
40-
// Constrained boolean by tx trace for enqueued call, #[IS_STATIC_NEXT_ROW] during normal execution,
41-
// IS_STATIC_IF_STATIC_CALL+IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT for nested calls,
42-
// and CTX_STACK_CALL for returns or failures.
36+
// Constrained boolean by tx trace (for enqueued call) and #[NEXT_IS_STATIC] for nested
4337
pol commit is_static;
4438

4539
pol commit parent_calldata_addr;
@@ -195,12 +189,7 @@ namespace execution;
195189
// otherwise = 0 ==> is_static' = is_static
196190
#[IS_STATIC_NEXT_ROW]
197191
NOT_LAST_EXEC * DEFAULT_CTX_ROW * (is_static' - is_static) = 0;
198-
// An external call from a non-static context only creates a nested static context if the opcode is STATICCALL.
199-
#[IS_STATIC_IF_STATIC_CALL]
200-
NOT_LAST_EXEC * sel_enter_call * (1 - is_static) * (is_static' - sel_execute_static_call) = 0;
201-
// An external call from a static context always creates a nested static context.
202-
#[IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT]
203-
NOT_LAST_EXEC * sel_enter_call * is_static * (is_static' - 1) = 0;
192+
NOT_LAST_EXEC * sel_enter_call * (is_static' - sel_execute_static_call) = 0;
204193

205194
// nested_exit_call = 1 ==> constraints come from lookup
206195
// sel_enter_call = 1 ==> parent_calldata_addr' = rop[4] (resolved operand 5 from execution trace)

barretenberg/cpp/pil/vm2/execution.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ sel_bytecode_retrieval_success {
147147

148148
pol commit sel_instruction_fetching_success;
149149
// If sel = 0, we want sel_instruction_fetching_success = 0. We shouldn't be using it.
150-
sel_instruction_fetching_success = sel_bytecode_retrieval_success * (1 - sel_instruction_fetching_failure);
150+
sel_instruction_fetching_success = sel * (1 - sel_instruction_fetching_failure);
151151

152152
#[INSTRUCTION_FETCHING_BODY]
153153
sel_instruction_fetching_success {

barretenberg/cpp/pil/vm2/tx.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ namespace tx;
306306
execution.enqueued_call_end {
307307
execution.context_id,
308308
execution.next_context_id,
309-
execution.sel_failure,
309+
execution.sel_error,
310310
execution.discard,
311311
// Tree State
312312
execution.note_hash_tree_root,

barretenberg/cpp/src/barretenberg/vm2/constraining/relations/context.test.cpp

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,21 @@ TEST(ContextConstrainingTest, ContextSwitchingCallReturn)
6161
{ C::execution_context_id, 1 },
6262
{ C::execution_next_context_id, 2 },
6363
{ C::execution_bytecode_id, top_bytecode_id },
64-
{ C::execution_is_static, 0 }, // Non-static context
6564
{ C::execution_parent_l2_gas_limit, 2000 },
6665
{ C::execution_parent_da_gas_limit, 4000 },
6766
{ C::execution_parent_l2_gas_used, 500 },
6867
{ C::execution_parent_da_gas_used, 1500 },
69-
{ C::execution_enqueued_call_start, 1 },
7068
},
7169
// CALL
7270
{
7371
{ C::execution_sel, 1 },
7472
{ C::execution_pc, 1 },
7573
{ C::execution_next_pc, 2 },
7674
{ C::execution_sel_execute_call, 1 },
77-
{ C::execution_sel_execute_static_call, 0 }, // Regular CALL, not STATICCALL
7875
{ C::execution_sel_enter_call, 1 },
7976
{ C::execution_context_id, 1 },
8077
{ C::execution_next_context_id, 2 },
8178
{ C::execution_bytecode_id, top_bytecode_id }, // Same as previous row (propagated)
82-
{ C::execution_is_static, 0 }, // Still non-static
8379
{ C::execution_rop_4_, /*cd offset=*/10 },
8480
{ C::execution_register_2_, /*contract address=*/0xdeadbeef },
8581
{ C::execution_register_3_, /*cd size=*/1 },
@@ -100,7 +96,6 @@ TEST(ContextConstrainingTest, ContextSwitchingCallReturn)
10096
{ C::execution_has_parent_ctx, 1 },
10197
{ C::execution_contract_address, 0xdeadbeef },
10298
{ C::execution_bytecode_id, nested_bytecode_id }, // New bytecode_id on entering new context
103-
{ C::execution_is_static, 0 }, // Remains non-static after regular CALL
10499
{ C::execution_parent_calldata_addr, 10 },
105100
{ C::execution_parent_calldata_size, 1 },
106101
},
@@ -638,137 +633,6 @@ TEST(ContextConstrainingTest, BytecodeIdPropagation)
638633
"BYTECODE_ID_NEXT_ROW"); // Should fail constraint
639634
}
640635

641-
TEST(ContextConstrainingTest, IsStaticRegularCallFromNonStaticContext)
642-
{
643-
// Non-static context making a regular CALL - should remain non-static
644-
TestTraceContainer trace({
645-
{ { C::precomputed_first_row, 1 } },
646-
{
647-
{ C::execution_sel, 1 },
648-
{ C::execution_context_id, 1 },
649-
{ C::execution_next_context_id, 2 },
650-
{ C::execution_is_static, 0 }, // Non-static context
651-
{ C::execution_sel_enter_call, 1 },
652-
{ C::execution_sel_execute_call, 1 }, // Regular CALL
653-
{ C::execution_sel_execute_static_call, 0 },
654-
},
655-
{
656-
{ C::execution_sel, 1 },
657-
{ C::execution_context_id, 2 },
658-
{ C::execution_next_context_id, 3 },
659-
{ C::execution_is_static, 0 }, // Should remain non-static
660-
},
661-
});
662-
check_relation<context>(
663-
trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT);
664-
665-
// Negative test: change is_static
666-
// regular call from non-static context cannot become static
667-
trace.set(C::execution_is_static, 2, 1);
668-
EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_STATIC_CALL),
669-
"IS_STATIC_IF_STATIC_CALL");
670-
671-
// reset is_static
672-
trace.set(C::execution_is_static, 2, 0);
673-
}
674-
675-
TEST(ContextConstrainingTest, IsStaticStaticCallFromNonStaticContext)
676-
{
677-
// Non-static context making a STATICCALL - should become static
678-
TestTraceContainer trace({
679-
{ { C::precomputed_first_row, 1 } },
680-
{
681-
{ C::execution_sel, 1 },
682-
{ C::execution_context_id, 1 },
683-
{ C::execution_next_context_id, 2 },
684-
{ C::execution_is_static, 0 }, // Non-static context
685-
{ C::execution_sel_enter_call, 1 },
686-
{ C::execution_sel_execute_call, 0 },
687-
{ C::execution_sel_execute_static_call, 1 }, // STATICCALL
688-
},
689-
{
690-
{ C::execution_sel, 1 },
691-
{ C::execution_context_id, 2 },
692-
{ C::execution_next_context_id, 3 },
693-
{ C::execution_is_static, 1 }, // Should become static
694-
},
695-
});
696-
check_relation<context>(
697-
trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT);
698-
699-
// Negative test: change is_static
700-
// static call from non-static context MUST become static
701-
trace.set(C::execution_is_static, 2, 0);
702-
EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_STATIC_CALL),
703-
"IS_STATIC_IF_STATIC_CALL");
704-
705-
// reset is_static
706-
trace.set(C::execution_is_static, 2, 1);
707-
}
708-
709-
TEST(ContextConstrainingTest, IsStaticCallFromStaticContext)
710-
{
711-
// Static context making any call - must remain static
712-
TestTraceContainer trace({
713-
{ { C::precomputed_first_row, 1 } },
714-
{
715-
{ C::execution_sel, 1 },
716-
{ C::execution_context_id, 1 },
717-
{ C::execution_next_context_id, 2 },
718-
{ C::execution_is_static, 1 }, // Static context
719-
{ C::execution_sel_enter_call, 1 },
720-
{ C::execution_sel_execute_call, 1 }, // Regular CALL
721-
{ C::execution_sel_execute_static_call, 0 },
722-
},
723-
{
724-
{ C::execution_sel, 1 },
725-
{ C::execution_context_id, 2 },
726-
{ C::execution_next_context_id, 3 },
727-
{ C::execution_is_static, 1 }, // Must remain static
728-
},
729-
});
730-
check_relation<context>(
731-
trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT);
732-
733-
// Negative test: change is_static
734-
// static call from static context MUST remain static
735-
trace.set(C::execution_is_static, 2, 0);
736-
EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT),
737-
"IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT");
738-
739-
// reset is_static
740-
trace.set(C::execution_is_static, 2, 1);
741-
}
742-
743-
TEST(ContextConstrainingTest, IsStaticPropagationWithoutCalls)
744-
{
745-
// is_static propagation without calls
746-
TestTraceContainer trace({
747-
{ { C::precomputed_first_row, 1 } },
748-
{
749-
{ C::execution_sel, 1 },
750-
{ C::execution_context_id, 1 },
751-
{ C::execution_next_context_id, 1 },
752-
{ C::execution_is_static, 1 }, // Static context
753-
},
754-
{
755-
{ C::execution_sel, 1 },
756-
{ C::execution_context_id, 1 },
757-
{ C::execution_next_context_id, 1 },
758-
{ C::execution_is_static, 1 }, // Should propagate
759-
},
760-
});
761-
check_relation<context>(trace, context::SR_IS_STATIC_NEXT_ROW);
762-
763-
// Negative test: change is_static
764-
// staticness must propagate without calls
765-
trace.set(C::execution_is_static, 2, 0);
766-
EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_NEXT_ROW), "IS_STATIC_NEXT_ROW");
767-
768-
// reset is_static
769-
trace.set(C::execution_is_static, 2, 1);
770-
}
771-
772636
TEST(ContextConstrainingTest, ContextIdPropagation)
773637
{
774638
TestTraceContainer trace({

barretenberg/cpp/src/barretenberg/vm2/generated/relations/alu_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void aluImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
138138
}
139139
{ // C_TAG_CHECK
140140
using Accumulator = typename std::tuple_element_t<8, ContainerOverSubrelations>;
141-
auto tmp = (FF(1) - in.get(C::alu_sel_err)) * (alu_EXPECTED_C_TAG - in.get(C::alu_ic_tag));
141+
auto tmp = (FF(1) - in.get(C::alu_sel_tag_err)) * (alu_EXPECTED_C_TAG - in.get(C::alu_ic_tag));
142142
tmp *= scaling_factor;
143143
std::get<8>(evals) += typename Accumulator::View(tmp);
144144
}

0 commit comments

Comments
 (0)