-
Notifications
You must be signed in to change notification settings - Fork 595
feat!: a static context propagates staticness to nested calls, even those that are not static calls. #16670
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!: a static context propagates staticness to nested calls, even those that are not static calls. #16670
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 |
|---|---|---|
|
|
@@ -61,21 +61,25 @@ TEST(ContextConstrainingTest, ContextSwitchingCallReturn) | |
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 2 }, | ||
| { C::execution_bytecode_id, top_bytecode_id }, | ||
| { C::execution_is_static, 0 }, // Non-static context | ||
| { C::execution_parent_l2_gas_limit, 2000 }, | ||
| { C::execution_parent_da_gas_limit, 4000 }, | ||
| { C::execution_parent_l2_gas_used, 500 }, | ||
| { C::execution_parent_da_gas_used, 1500 }, | ||
| { C::execution_enqueued_call_start, 1 }, | ||
| }, | ||
| // CALL | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_pc, 1 }, | ||
| { C::execution_next_pc, 2 }, | ||
| { C::execution_sel_execute_call, 1 }, | ||
| { C::execution_sel_execute_static_call, 0 }, // Regular CALL, not STATICCALL | ||
| { C::execution_sel_enter_call, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 2 }, | ||
| { C::execution_bytecode_id, top_bytecode_id }, // Same as previous row (propagated) | ||
| { C::execution_is_static, 0 }, // Still non-static | ||
| { C::execution_rop_4_, /*cd offset=*/10 }, | ||
| { C::execution_register_2_, /*contract address=*/0xdeadbeef }, | ||
| { C::execution_register_3_, /*cd size=*/1 }, | ||
|
|
@@ -96,6 +100,7 @@ TEST(ContextConstrainingTest, ContextSwitchingCallReturn) | |
| { C::execution_has_parent_ctx, 1 }, | ||
| { C::execution_contract_address, 0xdeadbeef }, | ||
| { C::execution_bytecode_id, nested_bytecode_id }, // New bytecode_id on entering new context | ||
| { C::execution_is_static, 0 }, // Remains non-static after regular CALL | ||
| { C::execution_parent_calldata_addr, 10 }, | ||
| { C::execution_parent_calldata_size, 1 }, | ||
| }, | ||
|
|
@@ -633,6 +638,137 @@ TEST(ContextConstrainingTest, BytecodeIdPropagation) | |
| "BYTECODE_ID_NEXT_ROW"); // Should fail constraint | ||
| } | ||
|
|
||
| TEST(ContextConstrainingTest, IsStaticRegularCallFromNonStaticContext) | ||
| { | ||
| // Non-static context making a regular CALL - should remain non-static | ||
| TestTraceContainer trace({ | ||
| { { C::precomputed_first_row, 1 } }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 2 }, | ||
| { C::execution_is_static, 0 }, // Non-static context | ||
| { C::execution_sel_enter_call, 1 }, | ||
| { C::execution_sel_execute_call, 1 }, // Regular CALL | ||
| { C::execution_sel_execute_static_call, 0 }, | ||
| }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 2 }, | ||
| { C::execution_next_context_id, 3 }, | ||
| { C::execution_is_static, 0 }, // Should remain non-static | ||
| }, | ||
| }); | ||
| check_relation<context>( | ||
| trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT); | ||
|
|
||
| // Negative test: change is_static | ||
| // regular call from non-static context cannot become static | ||
| trace.set(C::execution_is_static, 2, 1); | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_STATIC_CALL), | ||
| "IS_STATIC_IF_STATIC_CALL"); | ||
|
|
||
| // reset is_static | ||
|
Contributor
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. Leftover? Not needed if this is the end of the test.
Contributor
Author
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 try to always "reset" mutated things like this in our cpp tests. Sometimes I do a few of them back-to-back. So this is just me trying to be consistent. |
||
| trace.set(C::execution_is_static, 2, 0); | ||
| } | ||
|
|
||
| TEST(ContextConstrainingTest, IsStaticStaticCallFromNonStaticContext) | ||
| { | ||
| // Non-static context making a STATICCALL - should become static | ||
| TestTraceContainer trace({ | ||
| { { C::precomputed_first_row, 1 } }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 2 }, | ||
| { C::execution_is_static, 0 }, // Non-static context | ||
| { C::execution_sel_enter_call, 1 }, | ||
| { C::execution_sel_execute_call, 0 }, | ||
| { C::execution_sel_execute_static_call, 1 }, // STATICCALL | ||
| }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 2 }, | ||
| { C::execution_next_context_id, 3 }, | ||
| { C::execution_is_static, 1 }, // Should become static | ||
| }, | ||
| }); | ||
| check_relation<context>( | ||
| trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT); | ||
|
|
||
| // Negative test: change is_static | ||
| // static call from non-static context MUST become static | ||
| trace.set(C::execution_is_static, 2, 0); | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_STATIC_CALL), | ||
| "IS_STATIC_IF_STATIC_CALL"); | ||
|
|
||
| // reset is_static | ||
|
Contributor
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. Same here. |
||
| trace.set(C::execution_is_static, 2, 1); | ||
| } | ||
|
|
||
| TEST(ContextConstrainingTest, IsStaticCallFromStaticContext) | ||
| { | ||
| // Static context making any call - must remain static | ||
| TestTraceContainer trace({ | ||
| { { C::precomputed_first_row, 1 } }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 2 }, | ||
| { C::execution_is_static, 1 }, // Static context | ||
| { C::execution_sel_enter_call, 1 }, | ||
| { C::execution_sel_execute_call, 1 }, // Regular CALL | ||
| { C::execution_sel_execute_static_call, 0 }, | ||
| }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 2 }, | ||
| { C::execution_next_context_id, 3 }, | ||
| { C::execution_is_static, 1 }, // Must remain static | ||
| }, | ||
| }); | ||
| check_relation<context>( | ||
| trace, context::SR_IS_STATIC_IF_STATIC_CALL, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT); | ||
|
|
||
| // Negative test: change is_static | ||
| // static call from static context MUST remain static | ||
| trace.set(C::execution_is_static, 2, 0); | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT), | ||
| "IS_STATIC_IF_CALL_FROM_STATIC_CONTEXT"); | ||
|
|
||
| // reset is_static | ||
|
Contributor
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. Same |
||
| trace.set(C::execution_is_static, 2, 1); | ||
| } | ||
|
|
||
| TEST(ContextConstrainingTest, IsStaticPropagationWithoutCalls) | ||
| { | ||
| // is_static propagation without calls | ||
| TestTraceContainer trace({ | ||
| { { C::precomputed_first_row, 1 } }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 1 }, | ||
| { C::execution_is_static, 1 }, // Static context | ||
| }, | ||
| { | ||
| { C::execution_sel, 1 }, | ||
| { C::execution_context_id, 1 }, | ||
| { C::execution_next_context_id, 1 }, | ||
| { C::execution_is_static, 1 }, // Should propagate | ||
| }, | ||
| }); | ||
| check_relation<context>(trace, context::SR_IS_STATIC_NEXT_ROW); | ||
|
|
||
| // Negative test: change is_static | ||
| // staticness must propagate without calls | ||
| trace.set(C::execution_is_static, 2, 0); | ||
| EXPECT_THROW_WITH_MESSAGE(check_relation<context>(trace, context::SR_IS_STATIC_NEXT_ROW), "IS_STATIC_NEXT_ROW"); | ||
|
|
||
| // reset is_static | ||
| trace.set(C::execution_is_static, 2, 1); | ||
|
Contributor
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. Same |
||
| } | ||
|
|
||
| TEST(ContextConstrainingTest, ContextIdPropagation) | ||
| { | ||
| TestTraceContainer trace({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.