-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
324 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printAdd( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty ADD"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} + ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${formatParam(result, dependencies)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("ADD") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printDiv( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty DIV"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} / ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${formatParam(result, dependencies)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("DIV") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printEq( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty EQ"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} == ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${formatParam(result, dependencies)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("EQ") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, parseNumber, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printGt( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty GT"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} > ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${parseNumber(result) ? "true" : "false"})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("GT") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, parseNumber, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printLt( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty LT"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} < ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${parseNumber(result) ? "true" : "false"})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("LT") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printMul( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty MUL"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} * ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${formatParam(result, dependencies)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("MUL") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, parseMemory, parseNumber, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
import { hexlify } from "ethers/lib/utils"; | ||
|
||
export async function printSha3( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 1) { | ||
console.log("Faulty SHA3"); | ||
return; | ||
} | ||
const start = parseNumber(stack.pop()!); | ||
const length = parseNumber(stack.pop()!); | ||
|
||
const memory = parseMemory(structLog.memory); | ||
const inputToBeHashed = hexlify(memory.slice(start, start + length)); | ||
|
||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(inputToBeHashed, dependencies)} => (${formatParam( | ||
result, | ||
dependencies | ||
)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("SHA3") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { colorLabel } from "../colors"; | ||
import { DEPTH_INDENTATION } from "../constants"; | ||
import { StructLog, TracerDependenciesExtended } from "../types"; | ||
import { parseHex, shallowCopyStack } from "../utils"; | ||
import { formatParam } from "../format/param"; | ||
import { formatGasCost } from "../format/gas-cost"; | ||
|
||
export async function printSub( | ||
structLog: StructLog, | ||
index: number, | ||
structLogs: StructLog[], | ||
dependencies: TracerDependenciesExtended | ||
) { | ||
const stack = shallowCopyStack(structLog.stack); | ||
if (stack.length < 2) { | ||
console.log("Faulty SUB"); | ||
return; | ||
} | ||
const a = parseHex(stack.pop()!); | ||
const b = parseHex(stack.pop()!); | ||
const stackAfter = shallowCopyStack(structLogs[index + 1].stack); | ||
const result = parseHex(stackAfter.pop()!); | ||
|
||
const str = `${formatParam(a, dependencies)} - ${formatParam( | ||
b, | ||
dependencies | ||
)} => (${formatParam(result, dependencies)})`; | ||
console.log( | ||
DEPTH_INDENTATION.repeat(structLog.depth) + | ||
colorLabel("SUB") + | ||
" " + | ||
str + | ||
formatGasCost(structLog, null, dependencies) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters