Skip to content

Commit

Permalink
Check for overflow in context_id increment (#443)
Browse files Browse the repository at this point in the history
* Range-check context increment

* Doc
  • Loading branch information
Nashtare authored Jul 25, 2024
1 parent ed6a657 commit 005f384
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions evm_arithmetization/src/cpu/kernel/asm/core/util.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 005f384

Please sign in to comment.