Skip to content

Commit

Permalink
refactor: export range_check inner shift and number of parts
Browse files Browse the repository at this point in the history
  • Loading branch information
zmalatrax committed Aug 2, 2024
1 parent b8df3b4 commit 2b8747a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/builtins/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SegmentValue } from 'primitives/segmentValue';

import { outputHandler } from './output';
import { CELLS_PER_PEDERSEN, pedersenHandler } from './pedersen';
import { rangeCheckHandler } from './rangeCheck';
import { rangeCheckHandler, RC_BITS, RC_BITS_96 } from './rangeCheck';
import { CELLS_PER_ECDSA, ecdsaHandler } from './ecdsa';
import { bitwiseHandler, CELLS_PER_BITWISE } from './bitwise';
import { CELLS_PER_EC_OP, ecOpHandler } from './ecop';
Expand All @@ -29,13 +29,13 @@ const BUILTIN_HANDLER: {
} = {
output: outputHandler,
pedersen: pedersenHandler,
range_check: rangeCheckHandler(128n),
range_check: rangeCheckHandler(RC_BITS),
ecdsa: ecdsaHandler,
bitwise: bitwiseHandler,
ec_op: ecOpHandler,
keccak: keccakHandler,
poseidon: poseidonHandler,
range_check96: rangeCheckHandler(96n),
range_check96: rangeCheckHandler(RC_BITS_96),
};

/** Getter of the object `BUILTIN_HANDLER` */
Expand Down
12 changes: 12 additions & 0 deletions src/builtins/rangeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { BuiltinHandler } from './builtin';
import { isFelt } from 'primitives/segmentValue';
import { ExpectedFelt } from 'errors/primitives';

export const INNER_RC_BOUND_SHIFT = 16;
export const INNER_RC_BOUND_MASK = 0xffffn;

export const RC_N_PARTS = 8;
export const RC_N_PARTS_96 = 6;

/** Bound exponent of the range_check builtin, `128`. */
export const RC_BITS = BigInt(INNER_RC_BOUND_SHIFT * RC_N_PARTS);

/** Bound exponent of the range_check96 builtin, `96`. */
export const RC_BITS_96 = BigInt(INNER_RC_BOUND_SHIFT * RC_N_PARTS_96);

export const rangeCheckHandler = (boundExponent: bigint): BuiltinHandler => {
return {
set(target, prop, newValue): boolean {
Expand Down

0 comments on commit 2b8747a

Please sign in to comment.