Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devnet-5: bug fixes for 7702 #8148

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright contributors to Besu.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.evm.operation;

import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.evm.account.Account;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.evm.worldstate.DelegateCodeHelper;

import org.apache.tuweni.bytes.Bytes;

/**
* ExtCode* operations treat EOAs with delegated code differently than other operations. This
* abstract class contains common methods for this behaviour.
*/
abstract class AbstractExtCodeOperation extends AbstractOperation {
/**
* Instantiates a new Abstract operation.
*
* @param opcode the opcode
* @param name the name
* @param stackItemsConsumed the stack items consumed
* @param stackItemsProduced the stack items produced
* @param gasCalculator the gas calculator
*/
protected AbstractExtCodeOperation(
final int opcode,
final String name,
final int stackItemsConsumed,
final int stackItemsProduced,
final GasCalculator gasCalculator) {
super(opcode, name, stackItemsConsumed, stackItemsProduced, gasCalculator);
}

/**
* Returns the code for standard accounts or a special designator for EOAs with delegated code
*
* @param account The account
* @return the code or the special 7702 designator
*/
protected static Bytes getCode(final Account account) {
if (account == null) {
return Bytes.EMPTY;
}

return account.hasDelegatedCode()
? DelegateCodeHelper.getDelegatedCodeForRead()
: account.getCode();
}

/**
* Returns the code hash for standard accounts or a special designator for EOAs with delegated
* code
*
* @param account The account
* @return the code hash or the hash of the special 7702 designator
*/
protected static Hash getCodeHash(final Account account) {
if (account.hasDelegatedCode()) {
return Hash.hash(DelegateCodeHelper.getDelegatedCodeForRead());
}

return account.getCodeHash();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.gascalculator.GasCalculator;
import org.hyperledger.besu.evm.internal.Words;
import org.hyperledger.besu.evm.worldstate.DelegateCodeHelper;

import org.apache.tuweni.bytes.Bytes;

/** The Ext code copy operation. */
public class ExtCodeCopyOperation extends AbstractOperation {
public class ExtCodeCopyOperation extends AbstractExtCodeOperation {

/** This is the "code" legacy contracts see when copying code from an EOF contract. */
public static final Bytes EOF_REPLACEMENT_CODE = Bytes.fromHexString("0xef00");
Expand Down Expand Up @@ -108,14 +107,4 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {

return new OperationResult(cost, null);
}

private static Bytes getCode(final Account account) {
if (account == null) {
return Bytes.EMPTY;
}

return account.hasDelegatedCode()
? DelegateCodeHelper.getDelegatedCodeForRead()
: account.getCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import org.hyperledger.besu.evm.internal.OverflowException;
import org.hyperledger.besu.evm.internal.UnderflowException;
import org.hyperledger.besu.evm.internal.Words;
import org.hyperledger.besu.evm.worldstate.DelegateCodeHelper;

import org.apache.tuweni.bytes.Bytes;

/** The Ext code hash operation. */
public class ExtCodeHashOperation extends AbstractOperation {
public class ExtCodeHashOperation extends AbstractExtCodeOperation {

// // 0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5
static final Hash EOF_REPLACEMENT_HASH = Hash.hash(ExtCodeCopyOperation.EOF_REPLACEMENT_CODE);
Expand Down Expand Up @@ -93,7 +92,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
&& code.get(1) == 0) {
frame.pushStackItem(EOF_REPLACEMENT_HASH);
} else {
frame.pushStackItem(account.getCodeHash());
frame.pushStackItem(getCodeHash(account));
}
}
return new OperationResult(cost, null);
Expand All @@ -104,12 +103,4 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
return new OperationResult(cost(true), ExceptionalHaltReason.TOO_MANY_STACK_ITEMS);
}
}

private static Bytes getCode(final Account account) {
if (!account.hasDelegatedCode()) {
return account.getCode();
}

return DelegateCodeHelper.getDelegatedCodeForRead();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
import org.hyperledger.besu.evm.internal.OverflowException;
import org.hyperledger.besu.evm.internal.UnderflowException;
import org.hyperledger.besu.evm.internal.Words;
import org.hyperledger.besu.evm.worldstate.DelegateCodeHelper;

import org.apache.tuweni.bytes.Bytes;

/** The Ext code size operation. */
public class ExtCodeSizeOperation extends AbstractOperation {
public class ExtCodeSizeOperation extends AbstractExtCodeOperation {

static final Bytes EOF_SIZE = Bytes.of(2);

Expand Down Expand Up @@ -103,14 +102,4 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
return new OperationResult(cost(true), ExceptionalHaltReason.TOO_MANY_STACK_ITEMS);
}
}

private static Bytes getCode(final Account account) {
if (account == null) {
return Bytes.EMPTY;
}

return account.hasDelegatedCode()
? DelegateCodeHelper.getDelegatedCodeForRead()
: account.getCode();
}
}
Loading