From 005f38438243da050e5bb49498bdc324cd728ed9 Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Thu, 25 Jul 2024 08:56:00 -0400 Subject: [PATCH] Check for overflow in `context_id` increment (#443) * Range-check context increment * Doc --- evm_arithmetization/src/cpu/kernel/asm/core/util.asm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm index 6b48428ef..26478d0da 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm @@ -12,6 +12,17 @@ // stack: (empty) %mload_global_metadata(@GLOBAL_METADATA_LARGEST_CONTEXT) %add_const(0x10000000000000000) // scale each context by 2^64 + // stack: new_ctx + DUP1 + + // Memory addresses are represented as `ctx.2^64 + segment.2^32 + offset`, + // each address component expected to fit in a 32-bit limb. + // We enforce here that the new context id won't overflow. + PUSH 0xffffffffffffffffffffffff // 2^96 - 1 + // stack: max, new_ctx, new_ctx + LT + %jumpi(fault_exception) + // stack: new_ctx DUP1 %mstore_global_metadata(@GLOBAL_METADATA_LARGEST_CONTEXT)