Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Rewrite some calculations in terms of PUSH0
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed Feb 15, 2023
1 parent 4577d38 commit e12df19
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/code-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function parseCode(
name: parseOpcode(code[pc])
};
if (opcode.name.slice(0, 4) === "PUSH") {
const length = code[pc] - 0x60 + 1; //0x60 is code for PUSH1
const length = code[pc] - 0x5f; //0x5f is code for PUSH0
let pushData = code.subarray(pc + 1, pc + length + 1);
if (pushData.length < length) {
//if we run out of bytes for our pushdata, fill the rest
Expand Down
4 changes: 1 addition & 3 deletions packages/codec/lib/abi-data/allocate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,7 @@ function constructorOutputAllocation(
if (contractKind === "library") {
//note: I am relying on this being present!
//(also this part is a bit HACKy)
const pushAddressInstruction = (0x60 + Evm.Utils.ADDRESS_SIZE - 1).toString(
16
); //"73"
const pushAddressInstruction = (0x5f + Evm.Utils.ADDRESS_SIZE).toString(16); //"73"
const delegateCallGuardString =
"0x" + pushAddressInstruction + "..".repeat(Evm.Utils.ADDRESS_SIZE);
if (binary.startsWith(delegateCallGuardString)) {
Expand Down
8 changes: 2 additions & 6 deletions packages/codec/lib/contexts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ export function normalizeContexts(contexts: Contexts): Contexts {
//now we must handle the delegatecall guard -- 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"
const pushAddressInstruction = (0x5f + Evm.Utils.ADDRESS_SIZE).toString(16); //"73"
for (let context of Object.values(newContexts)) {
if (context.contractKind === "library" && !context.isConstructor) {
context.binary = context.binary.replace(
Expand Down Expand Up @@ -401,9 +399,7 @@ function contractKind(
const deployedBytecode = Shims.NewToLegacy.forBytecode(
contract.deployedBytecode
);
const pushAddressInstruction = (0x60 + Evm.Utils.ADDRESS_SIZE - 1).toString(
16
); //"73"
const pushAddressInstruction = (0x5f + Evm.Utils.ADDRESS_SIZE).toString(16); //"73"
const libraryString =
"0x" + pushAddressInstruction + "00".repeat(Evm.Utils.ADDRESS_SIZE);
return deployedBytecode.startsWith(libraryString) ? "library" : "contract";
Expand Down

0 comments on commit e12df19

Please sign in to comment.