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

Only append contract data param at context creation step #209

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ pil-config.json
parallel-tests
verbose-config.json
*.stats
tools/full-tracer-tests/geth-traces/
14 changes: 9 additions & 5 deletions src/sm/sm_main/debug/full-tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,20 @@ class FullTracer {
singleInfo.error = '';
singleInfo.state_root = bnToPaddedHex(fea2scalar(ctx.Fr, ctx.SR), 64);

// Check previous step
const prevStep = this.execution_trace[this.execution_trace.length - 1];

// Add contract info
singleInfo.contract = {};
singleInfo.contract.address = bnToPaddedHex(getVarFromCtx(ctx, false, 'txDestAddr'), 40);
singleInfo.contract.caller = bnToPaddedHex(getVarFromCtx(ctx, false, 'txSrcAddr'), 40);
singleInfo.contract.value = getVarFromCtx(ctx, false, 'txValue').toString();
const calldataCTX = getVarFromCtx(ctx, false, 'calldataCTX');
const calldataOffset = getVarFromCtx(ctx, false, 'calldataOffset');
singleInfo.contract.data = getFromMemory(calldataOffset, getVarFromCtx(ctx, false, 'txCalldataLen').toString(), ctx, calldataCTX);
// Only set contract data param if it has changed (new context created or context terminated) to not overflow the trace
if (prevStep && (opIncContext.includes(prevStep.opcode) || zeroCostOp.includes(prevStep.opcode))) {
const calldataCTX = getVarFromCtx(ctx, false, 'calldataCTX');
const calldataOffset = getVarFromCtx(ctx, false, 'calldataOffset');
singleInfo.contract.data = getFromMemory(calldataOffset, getVarFromCtx(ctx, false, 'txCalldataLen').toString(), ctx, calldataCTX);
}
singleInfo.contract.gas = this.txGAS[this.depth];
singleInfo.contract.type = 'CALL';

Expand Down Expand Up @@ -745,8 +751,6 @@ class FullTracer {
this.call_trace.push(singleCallTrace);
this.execution_trace.push(singleExecuteTrace);

// Check previous step
const prevStep = this.execution_trace[this.execution_trace.length - 2];
if (prevStep && opIncContext.includes(prevStep.opcode) && prevStep.depth !== singleInfo.depth) {
// Create new call data entry
this.callData[ctx.CTX] = { type: prevStep.opcode };
Expand Down
5 changes: 5 additions & 0 deletions tools/full-tracer-tests/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[
{
"folderName": "calldata",
"traceMethod": "callTracer",
"isEthereumTest": false
},
{
"testName": "op-invalid",
"testToDebug": 0,
Expand Down
8 changes: 5 additions & 3 deletions tools/full-tracer-tests/full-tracer-tests-prover.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ async function main() {
if (!fs.existsSync(path.join(__dirname, 'geth-traces'))) {
fs.mkdirSync(path.join(__dirname, 'geth-traces'));
}
// Compile rom file
const zkasmFile = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-rom/main/main.zkasm');
const rom = await zkasm.compile(zkasmFile, null, {});
for (const configTest of config) {
const {
testName, testToDebug, isEthereumTest, folderName, disable, traceMethod,
Expand Down Expand Up @@ -137,7 +140,7 @@ async function main() {
gethTraces = await getGethTrace(txsHashes, test.testName, traceMethod, test.id);
}
// Get trace from full tracer
const ftTxHashes = await getFtTrace(test.inputTestPath, test.testName, gethTraces.length);
const ftTxHashes = await getFtTrace(test.inputTestPath, test.testName, gethTraces.length, rom);

const input = JSON.parse(fs.readFileSync(test.inputTestPath, 'utf8'));
// Populate db with input bytecode
Expand Down Expand Up @@ -515,11 +518,10 @@ function compareDefaultTracer(geth, fullTracer, i) {
* @param {Number} txsCount Number of transactions executed
* @returns Array of tx hashes
*/
async function getFtTrace(inputPath, testName, txsCount) {
async function getFtTrace(inputPath, testName, txsCount, rom) {
const input = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
const poseidon = await buildPoseidon();
const { F } = poseidon;
const rom = JSON.parse(fs.readFileSync(path.join(__dirname, 'rom.json'), 'utf8'));
const fileCachePil = path.join(__dirname, '../../cache-main-pil.json');
let pil;
if (fs.existsSync(fileCachePil)) {
Expand Down
12 changes: 8 additions & 4 deletions tools/full-tracer-tests/full-tracer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { newCommitPolsArray, compile } = require('pilcom');
const buildPoseidon = require('@0xpolygonhermez/zkevm-commonjs').getPoseidon;
const _ = require('lodash');
const chalk = require('chalk');
const zkasm = require('@0xpolygonhermez/zkasmcom');
const smMain = require('../../src/sm/sm_main/sm_main');

const CHAIN_ID = 1000;
Expand Down Expand Up @@ -51,6 +52,9 @@ async function main() {
if (!fs.existsSync(path.join(__dirname, 'geth-traces'))) {
fs.mkdirSync(path.join(__dirname, 'geth-traces'));
}
// Compile rom file
const zkasmFile = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-rom/main/main.zkasm');
const rom = await zkasm.compile(zkasmFile, null, {});
for (const configTest of config) {
const {
testName, testToDebug, traceMethod, isEthereumTest, folderName, disable,
Expand Down Expand Up @@ -97,7 +101,7 @@ async function main() {
}

// Get trace from full tracer
const ftTraces = await getFtTrace(test.inputTestPath, test.testName, gethTraces.length);
const ftTraces = await getFtTrace(test.inputTestPath, test.testName, gethTraces.length, rom);

// Compare traces
for (let i = 0; i < ftTraces.length; i++) {
Expand All @@ -110,7 +114,7 @@ async function main() {
process.exit(1);
}
} else {
console.log(chalk.green(`No differences for test ${test.testName}-${test.id}-${i}`));
console.log(chalk.green(`No differences for test ${test.testName}-${test.id}-${i} -- ${traceMethod}`));
}
}
}
Expand Down Expand Up @@ -579,11 +583,11 @@ function compareTraces(geth, fullTracer) {
* @param {Number} txsCount Number of transactions executed
* @returns Array of full traces outputs
*/
async function getFtTrace(inputPath, testName, txsCount) {
async function getFtTrace(inputPath, testName, txsCount, rom) {
const input = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
const poseidon = await buildPoseidon();
const { F } = poseidon;
const rom = JSON.parse(fs.readFileSync(path.join(__dirname, 'rom.json'), 'utf8'));

const fileCachePil = path.join(__dirname, '../../cache-main-pil.json');
let pil;
if (fs.existsSync(fileCachePil)) {
Expand Down
38 changes: 38 additions & 0 deletions tools/full-tracer-tests/geth-traces/aa_0_callTracer_0_geth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"from": "0x4d5cf5032b2a844602278b01199ed191a86c93ff",
"gas": "0x186a0",
"gasUsed": "0x6bf4",
"to": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98",
"input": "0xc6c211e9000000000000000000000000569195834b7a9dfd4c587344c35a4c4ea2113f9700000000000000000000000000000000000000000000000000000000000007c0",
"error": "execution reverted",
"calls": [
{
"from": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98",
"gas": "0x11de3",
"gasUsed": "0x0",
"to": "0x569195834b7a9dfd4c587344c35a4c4ea2113f97",
"input": "0x6466414b00000000000000000000000000000000000000000000000000000000000007c0",
"value": "0x0",
"type": "CALL"
},
{
"from": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98",
"gas": "0x11a03",
"gasUsed": "0x0",
"to": "0x569195834b7a9dfd4c587344c35a4c4ea2113f97",
"input": "0x6466414b00000000000000000000000000000000000000000000000000000000000007c0",
"value": "0x0",
"type": "DELEGATECALL"
},
{
"from": "0x1275fbb540c8efc58b812ba83b0d0b8b9917ae98",
"gas": "0x11708",
"gasUsed": "0x0",
"to": "0x569195834b7a9dfd4c587344c35a4c4ea2113f97",
"input": "0x813d8a37",
"type": "STATICCALL"
}
],
"value": "0x0",
"type": "CALL"
}

Large diffs are not rendered by default.

Loading