Skip to content
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

Hadling negative hash address #328

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/sm/sm_main/sm_main_exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const byteMaskOn256 = Scalar.bor(Scalar.shl(Mask256, 256), Scalar.shr(Mask256, 8
const WarningCheck = 1;
const ErrorCheck = 2;

const MAX_HASH_ADDRESS = 0x100000000;

let fullTracer;
let debug;
let statsTracer;
Expand Down Expand Up @@ -677,6 +679,9 @@ module.exports = async function execute(pols, input, rom, config = {}, metadata
const anyHash = l.hashP || l.hashK || l.hashS || l.hashPDigest || l.hashKDigest || l.hashSDigest || l.hashPLen || l.hashKLen || l.hashSLen;
const memAddr = addr + (l.memUseAddrRel ? addrRel : 0);
const hashAddr = anyHash ? (l.hashOffset ?? 0) + fe2n(Fr, ctx.E[0]) : 0;
if (hashAddr < 0 || hashAddr >= MAX_HASH_ADDRESS) {
throw new Error(`Hash address (${hashAddr}) out of bounds ${sourceRef}`);
}


//////
Expand Down Expand Up @@ -1081,7 +1086,9 @@ module.exports = async function execute(pols, input, rom, config = {}, metadata
(!Fr.eq(ctx.A[6], op6)) ||
(!Fr.eq(ctx.A[7], op7))
) {
throw new Error(`Assert does not match ${sourceRef} (op:${[op0, op1, op2, op3, op4, op5, op6, op7]} A:${[ctx.A[0], ctx.A[1], ctx.A[2], ctx.A[3], ctx.A[4], ctx.A[5], ctx.A[6], ctx.A[7]]})`);
const op = [op0, op1, op2, op3, op4, op5, op6, op7];
const A = [ctx.A[0], ctx.A[1], ctx.A[2], ctx.A[3], ctx.A[4], ctx.A[5], ctx.A[6], ctx.A[7]];
throw new Error(`Assert does not match ${sourceRef}\n\top:[${op}] = ${fea2String(Fr,op)}\n\t A:[${A}] = ${fea2String(Fr,A)}`);
}
pols.assert[i] = 1n;
} else {
Expand Down