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

Commit

Permalink
Account for constructors in decodeCalldata re-encoding check
Browse files Browse the repository at this point in the history
  • Loading branch information
haltman-at committed May 25, 2023
1 parent 9065237 commit 81afc71
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/codec/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ export function* decodeCalldata(
decodedArgumentValues,
info.allocations.abi
);
const encodedData = info.state.calldata.subarray(Evm.Utils.SELECTOR_SIZE); //slice off the selector
//NOTE: I'm assuming this isn't a constructor. right now strict mode is only used
//for functions, not constructors. if this is a constructor than the above line
//won't work properly... you'd want to strip off the whole bytecode.
const selectorLength = isConstructor
? (context.binary.length - 2) / 2 //for a constructor, the bytecode acts as the "selector"
: //note we have to account for the fact that it's a hex string
Evm.Utils.SELECTOR_SIZE;
const encodedData = info.state.calldata.subarray(selectorLength); //slice off the selector
if (!Evm.Utils.equalData(reEncodedData, encodedData)) {
//if not, this allocation doesn't work
debug("rejected due to mismatch");
Expand Down

0 comments on commit 81afc71

Please sign in to comment.