Search in sources :

Example 1 with Account

use of org.hyperledger.besu.evm.account.Account in project hedera-services by hashgraph.

the class HederaSLoadOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    try {
        final Account account = frame.getWorldUpdater().get(frame.getRecipientAddress());
        final Address address = account.getAddress();
        final Bytes32 key = UInt256.fromBytes(frame.popStackItem());
        final boolean slotIsWarm = frame.warmUpStorage(address, key);
        final Optional<Gas> optionalCost = slotIsWarm ? warmCost : coldCost;
        if (frame.getRemainingGas().compareTo(optionalCost.orElse(Gas.ZERO)) < 0) {
            return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            UInt256 storageValue = account.getStorageValue(UInt256.fromBytes(key));
            if (dynamicProperties.shouldEnableTraceability()) {
                HederaOperationUtil.cacheExistingValue(frame, address, key, storageValue);
            }
            frame.pushStackItem(storageValue);
            return slotIsWarm ? warmSuccess : coldSuccess;
        }
    } catch (final UnderflowException ufe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    } catch (final OverflowException ofe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.TOO_MANY_STACK_ITEMS));
    }
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) Gas(org.hyperledger.besu.evm.Gas) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException) Bytes32(org.apache.tuweni.bytes.Bytes32) UInt256(org.apache.tuweni.units.bigints.UInt256)

Example 2 with Account

use of org.hyperledger.besu.evm.account.Account in project hedera-services by hashgraph.

the class GasCalculatorHederaV18Test method assertSelfDestructOperationGasCost.

@Test
void assertSelfDestructOperationGasCost() {
    Account recipient = mock(Account.class);
    assertEquals(Gas.of(0), gasCalculatorHedera.selfDestructOperationGasCost(recipient, Wei.of(10L)));
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Test(org.junit.jupiter.api.Test)

Example 3 with Account

use of org.hyperledger.besu.evm.account.Account in project hedera-services by hashgraph.

the class HederaOperationUtilTest method setOriginalReadValue.

@Test
void setOriginalReadValue() {
    given(messageFrame.getRecipientAddress()).willReturn(PRETEND_RECIPIENT_ADDR);
    given(messageFrame.popStackItem()).willReturn(Bytes.of(1));
    given(messageFrame.getWorldUpdater()).willReturn(hederaWorldUpdater);
    given(hederaWorldUpdater.parentUpdater()).willReturn(Optional.of(updater));
    var frameStack = new ArrayDeque<MessageFrame>();
    frameStack.add(messageFrame);
    given(messageFrame.getMessageFrameStack()).willReturn(frameStack);
    TreeMap<Address, Map<Bytes, Pair<Bytes, Bytes>>> map = new TreeMap<>();
    given(updater.getStateChanges()).willReturn(map);
    given(hederaWorldUpdater.get(PRETEND_RECIPIENT_ADDR)).willReturn(worldStateAccount);
    Bytes32 key = UInt256.fromBytes(messageFrame.popStackItem());
    Account account = messageFrame.getWorldUpdater().get(messageFrame.getRecipientAddress());
    HederaOperationUtil.cacheExistingValue(messageFrame, PRETEND_RECIPIENT_ADDR, key, account.getStorageValue(UInt256.fromBytes(key)));
    assertTrue(updater.getStateChanges().containsKey(PRETEND_RECIPIENT_ADDR));
    assertTrue(updater.getStateChanges().get(PRETEND_RECIPIENT_ADDR).containsKey(UInt256.ONE));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) TreeMap(java.util.TreeMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Bytes32(org.apache.tuweni.bytes.Bytes32) ArrayDeque(java.util.ArrayDeque) Test(org.junit.jupiter.api.Test)

Example 4 with Account

use of org.hyperledger.besu.evm.account.Account in project besu by hyperledger.

the class MainnetTransactionValidatorTest method shouldRejectTransactionWhenTransactionNonceBelowAccountNonce.

@Test
public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() {
    final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode);
    final Account account = accountWithNonce(basicTransaction.getNonce() + 1);
    assertThat(validator.validateForSender(basicTransaction, account, false)).isEqualTo(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_LOW));
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Test(org.junit.Test)

Example 5 with Account

use of org.hyperledger.besu.evm.account.Account in project besu by hyperledger.

the class MainnetTransactionValidatorTest method shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce.

@Test
public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() {
    final MainnetTransactionValidator validator = new MainnetTransactionValidator(gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode);
    final Transaction transaction = new TransactionTestFixture().nonce(11).createTransaction(senderKeys);
    final Account account = accountWithNonce(5);
    assertThat(validator.validateForSender(transaction, account, false)).isEqualTo(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE));
}
Also used : Account(org.hyperledger.besu.evm.account.Account) TransactionTestFixture(org.hyperledger.besu.ethereum.core.TransactionTestFixture) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Test(org.junit.Test)

Aggregations

Account (org.hyperledger.besu.evm.account.Account)56 Address (org.hyperledger.besu.datatypes.Address)24 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)19 Hash (org.hyperledger.besu.datatypes.Hash)18 Bytes (org.apache.tuweni.bytes.Bytes)15 Bytes32 (org.apache.tuweni.bytes.Bytes32)14 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)14 Test (org.junit.Test)13 Optional (java.util.Optional)12 WorldState (org.hyperledger.besu.evm.worldstate.WorldState)12 Map (java.util.Map)11 Wei (org.hyperledger.besu.datatypes.Wei)10 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)10 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)10 Transaction (org.hyperledger.besu.ethereum.core.Transaction)9 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HashSet (java.util.HashSet)7 Set (java.util.Set)7