Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//literal 38 :P
for (let context of Object.values(newContexts)) {
context.binary = context.binary.replace(genericRegexp, replacement);
}
debug("short replacements complete");
//but there's one more step -- libraries' deployedBytecode will include
//0s in place of their own address instead of a link reference at the
//beginning, so we need to account for that too
const pushAddressInstruction = (0x60 + Evm.Utils.ADDRESS_SIZE - 1).toString(
16
); //"73"
for (let context of Object.values(newContexts)) {
if (context.contractKind === "library" && !context.isConstructor) {
context.binary = context.binary.replace(
"0x" + pushAddressInstruction + "00".repeat(Evm.Utils.ADDRESS_SIZE),
"0x" + pushAddressInstruction + replacement
);
}
}
debug("extra library replacements complete");
//finally, return this mess!
return newContexts;
}
export function matchContext(
context: Context,
givenBinary: string
): boolean {
let { binary, isConstructor } = context;
let lengthDifference = givenBinary.length - binary.length;
//first: if it's not a constructor, they'd better be equal in length.
//if it is a constructor, the given binary must be at least as long,
//and the difference must be a multiple of 64
if (
(!isConstructor && lengthDifference !== 0) ||
lengthDifference < 0 ||
lengthDifference % (2 * Evm.Utils.WORD_SIZE) !== 0
) {
return false;
}
for (let i = 0; i < binary.length; i++) {
//note: using strings like arrays is kind of dangerous in general in JS,
//but everything here is ASCII so it's fine
//note that we need to compare case-insensitive, since Solidity will
//put addresses in checksum case in the compiled source
//(we don't actually need that second toLowerCase(), but whatever)
if (
binary[i] !== "." &&
binary[i].toLowerCase() !== givenBinary[i].toLowerCase()
) {
return false;
}
}