Skip to content

Commit

Permalink
moves check for init code length before balance check (hyperledger#5077)
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Florentine <[email protected]>
  • Loading branch information
jflo authored and ensi321 committed Feb 19, 2023
1 parent dc52888 commit aa40a7c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
final MutableAccount account = frame.getWorldUpdater().getAccount(address).getMutable();

frame.clearReturnData();
final long inputOffset = clampedToLong(frame.getStackItem(1));
final long inputSize = clampedToLong(frame.getStackItem(2));
if (inputSize > maxInitcodeSize) {
frame.popStackItems(getStackItemsConsumed());
return new OperationResult(cost, ExceptionalHaltReason.CODE_TOO_LARGE);
}

if (value.compareTo(account.getBalance()) > 0
|| frame.getMessageStackDepth() >= 1024
Expand All @@ -88,12 +94,6 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
} else {
account.incrementNonce();

final long inputOffset = clampedToLong(frame.getStackItem(1));
final long inputSize = clampedToLong(frame.getStackItem(2));
if (inputSize > maxInitcodeSize) {
frame.popStackItems(getStackItemsConsumed());
return new OperationResult(cost, ExceptionalHaltReason.CODE_TOO_LARGE);
}
final Bytes inputData = frame.readMemory(inputOffset, inputSize);
// Never cache CREATEx initcode. The amount of reuse is very low, and caching mostly
// addresses disk loading delay, and we already have the code.
Expand Down

0 comments on commit aa40a7c

Please sign in to comment.