From 6cc9456160a6da4474659cec7212c99e4ec5cb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Masip?= Date: Fri, 5 Apr 2024 18:05:56 +0200 Subject: [PATCH] Hadling negative hash address --- src/sm/sm_main/sm_main_exec.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sm/sm_main/sm_main_exec.js b/src/sm/sm_main/sm_main_exec.js index a98c5daa..ad479a68 100644 --- a/src/sm/sm_main/sm_main_exec.js +++ b/src/sm/sm_main/sm_main_exec.js @@ -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; @@ -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}`); + } ////// @@ -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 {