Skip to content

Commit

Permalink
Merge pull request #513 from 0xPolygonHermez/fractasy_dual_main_gener…
Browse files Browse the repository at this point in the history
…ator

Adapt main generator to conditionally support fork 4
  • Loading branch information
fractasy authored Aug 22, 2023
2 parents c62870b + 4bf7a5d commit 873bd28
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions src/main_generator/main_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,14 +825,45 @@ string generate(const json &rom, const string &functionName, const string &fileN
if (bAddrRel)
{
code += " // If addrRel is possitive, and the sum is too big, fail\n";
code += " if ( addrRel >= " + to_string( ( (rom["program"][zkPC].contains("isMem") && (rom["program"][zkPC]["isMem"] == 1) ) ? 0x20000 : 0x10000 ) - 2048 ) + ")\n";
code += " {\n";
code += " proverRequest.result = ZKR_SM_MAIN_ADDRESS_OUT_OF_RANGE;\n";
code += " zkPC=" + to_string(zkPC) +";\n";
code += " mainExecutor.logError(ctx, \"addrRel too big addrRel=\" + to_string(addrRel));\n";
code += " HashDBClientFactory::freeHashDBClient(pHashDB);\n";
code += " return;\n";
code += " }\n";

if (forkNamespace == "fork_4")
{

code += " if (proverRequest.input.publicInputsExtended.publicInputs.oldBatchNum > 382000)\n";
code += " {\n";
code += " if ( addrRel >= " + to_string( ( (rom["program"][zkPC].contains("isMem") && (rom["program"][zkPC]["isMem"] == 1) ) ? 0x20000 : 0x10000 ) - 2048 ) + ")\n";
code += " {\n";
code += " proverRequest.result = ZKR_SM_MAIN_ADDRESS_OUT_OF_RANGE;\n";
code += " zkPC=" + to_string(zkPC) +";\n";
code += " mainExecutor.logError(ctx, \"addrRel too big addrRel=\" + to_string(addrRel));\n";
code += " HashDBClientFactory::freeHashDBClient(pHashDB);\n";
code += " return;\n";
code += " }\n";
code += " }\n";
code += " else\n";
code += " {\n";
code += " if (addrRel>=0x20000 || ((rom.line[" + to_string(zkPC) + "].isMem==1) && (addrRel >= 0x10000)))\n";
code += " {\n";
code += " proverRequest.result = ZKR_SM_MAIN_ADDRESS_OUT_OF_RANGE;\n";
code += " zkPC=" + to_string(zkPC) +";\n";
code += " mainExecutor.logError(ctx, \"addrRel too big addrRel=\" + to_string(addrRel));\n";
code += " HashDBClientFactory::freeHashDBClient(pHashDB);\n";
code += " return;\n";
code += " }\n";
code += " }\n";
}
else
{
code += " if ( addrRel >= " + to_string( ( (rom["program"][zkPC].contains("isMem") && (rom["program"][zkPC]["isMem"] == 1) ) ? 0x20000 : 0x10000 ) - 2048 ) + ")\n";
code += " {\n";
code += " proverRequest.result = ZKR_SM_MAIN_ADDRESS_OUT_OF_RANGE;\n";
code += " zkPC=" + to_string(zkPC) +";\n";
code += " mainExecutor.logError(ctx, \"addrRel too big addrRel=\" + to_string(addrRel));\n";
code += " HashDBClientFactory::freeHashDBClient(pHashDB);\n";
code += " return;\n";
code += " }\n";
}

code += " // If addrRel is negative, fail\n";
code += " if (addrRel < 0)\n";
code += " {\n";
Expand Down Expand Up @@ -2876,7 +2907,7 @@ string generate(const json &rom, const string &functionName, const string &fileN
code += " }\n";
code += " if (!hashIterator->second.digestCalled)\n";
code += " {\n";

code += " // Get a local copy of the bytes vector\n";
code += " vector<uint8_t> data = hashIterator->second.data;\n";

Expand Down

0 comments on commit 873bd28

Please sign in to comment.