Skip to content

Commit 39c3b1a

Browse files
committed
refactor: export range_check inner shift and number of parts
1 parent e65c92f commit 39c3b1a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/builtins/builtin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SegmentValue } from 'primitives/segmentValue';
22

33
import { outputHandler } from './output';
44
import { CELLS_PER_PEDERSEN, pedersenHandler } from './pedersen';
5-
import { rangeCheckHandler } from './rangeCheck';
5+
import { rangeCheckHandler, RC_BITS, RC_BITS_96 } from './rangeCheck';
66
import { CELLS_PER_ECDSA, ecdsaHandler } from './ecdsa';
77
import { bitwiseHandler, CELLS_PER_BITWISE } from './bitwise';
88
import { CELLS_PER_EC_OP, ecOpHandler } from './ecop';
@@ -30,13 +30,13 @@ const BUILTIN_HANDLER: {
3030
} = {
3131
output: outputHandler,
3232
pedersen: pedersenHandler,
33-
range_check: rangeCheckHandler(128n),
33+
range_check: rangeCheckHandler(RC_BITS),
3434
ecdsa: ecdsaHandler,
3535
bitwise: bitwiseHandler,
3636
ec_op: ecOpHandler,
3737
keccak: keccakHandler,
3838
poseidon: poseidonHandler,
39-
range_check96: rangeCheckHandler(96n),
39+
range_check96: rangeCheckHandler(RC_BITS_96),
4040
segment_arena: segmentArenaHandler,
4141
};
4242

src/builtins/rangeCheck.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ import { BuiltinHandler } from './builtin';
33
import { isFelt } from 'primitives/segmentValue';
44
import { ExpectedFelt } from 'errors/primitives';
55

6+
export const INNER_RC_BOUND_SHIFT = 16;
7+
export const INNER_RC_BOUND_MASK = 0xffffn;
8+
9+
export const RC_N_PARTS = 8;
10+
export const RC_N_PARTS_96 = 6;
11+
12+
/** Bound exponent of the range_check builtin, `128`. */
13+
export const RC_BITS = BigInt(INNER_RC_BOUND_SHIFT * RC_N_PARTS);
14+
15+
/** Bound exponent of the range_check96 builtin, `96`. */
16+
export const RC_BITS_96 = BigInt(INNER_RC_BOUND_SHIFT * RC_N_PARTS_96);
17+
618
export const rangeCheckHandler = (boundExponent: bigint): BuiltinHandler => {
719
return {
820
set(target, prop, newValue): boolean {

0 commit comments

Comments
 (0)