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));
}
}
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)));
}
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));
}
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));
}
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));
}
Aggregations