Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -490,15 +490,6 @@ public void addCreatedEvmAddressTo(
resultBuilder.evmAddress(evmAddress);
}

public void addSignerNonce(
@Nullable final AccountID senderId,
@NonNull final ContractFunctionResult.Builder derivedBuilder,
@NonNull final List<StateChange> remainingStateChanges) {
if (senderId != null) {
derivedBuilder.signerNonce(getSignerNonce(senderId, remainingStateChanges));
}
}

public void toggleNoncesExternalization(final boolean externalizeNonces) {
this.externalizeNonces = externalizeNonces;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.hedera.hapi.block.stream.output.TransactionOutput;
import com.hedera.hapi.block.stream.trace.ExecutedInitcode;
import com.hedera.hapi.block.stream.trace.TraceData;
import com.hedera.hapi.node.base.AccountID;
import com.hedera.hapi.node.base.FileID;
import com.hedera.hapi.node.base.HookId;
import com.hedera.hapi.node.base.ResponseCodeEnum;
Expand Down Expand Up @@ -152,25 +151,8 @@ public SingleTransactionRecord translate(
derivedBuilder, evmResult.contractNonces());
}
}
if (knownCreation) {
if (!PRE_NONCE_ERROR_MESSAGE.equals(evmResult.errorMessage())) {
baseTranslator.addSignerNonce(
evmResult.senderId(), derivedBuilder, remainingStateChanges);
}
} else {
if (!PRE_NONCE_ERROR_MESSAGE.equals(evmResult.errorMessage())) {
if (parts.isBatchScoped() && finalEthTxData != null) {
handleBatchScopedNonce(
evmResult.senderId(),
finalEthTxData.nonce(),
derivedBuilder,
baseTranslator,
remainingStateChanges);
} else {
baseTranslator.addSignerNonce(
evmResult.senderId(), derivedBuilder, remainingStateChanges);
}
}
if (!PRE_NONCE_ERROR_MESSAGE.equals(evmResult.errorMessage())) {
derivedBuilder.signerNonce(evmResult.signerNonce());
}
final var fnResult = derivedBuilder.build();
if (knownCreation) {
Expand All @@ -188,19 +170,4 @@ public SingleTransactionRecord translate(
followingUnitTraces,
executingHookId);
}

private void handleBatchScopedNonce(
AccountID senderId,
long currentNonce,
ContractFunctionResult.Builder builder,
BaseTranslator baseTranslator,
List<StateChange> remainingStateChanges) {
if (baseTranslator.isNonceIncremented(senderId, currentNonce, remainingStateChanges)) {
// If we have multiple ethereum transactions in a batch, and they increment the same nonce,
// we have to derive the nonce from the input for the transactions that are in the middle of the batch.
builder.signerNonce(currentNonce + 1L);
} else {
baseTranslator.addSignerNonce(senderId, builder, remainingStateChanges);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE;
import static com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.esaulpaugh.headlong.abi.Address;
import com.google.protobuf.ByteString;
Expand Down Expand Up @@ -63,7 +62,7 @@ public class CodeDelegationAtomicBatchTest {
private static final String CODE_DELEGATION_CONTRACT_2 = "CodeDelegationContract2";
private static final AtomicReference<Address> DELEGATION_TARGET = new AtomicReference<>();
private static final AtomicReference<Address> DELEGATION_TARGET_2 = new AtomicReference<>();
private static final String CONTRACT = "CreateTrivial";
private static final String CONTRACT = "Multipurpose";
private static final String REVERTING_CONTRACT = "InternalCallee";
private static final String DELEGATION_SET = "DelegationSet";
private static final String CRYPTO_CREATE_DELEGATING_ACCOUNT = "CryptoCreateDelegatingAccount";
Expand Down Expand Up @@ -110,7 +109,7 @@ final Stream<DynamicTest> testDelegationCommitedInSuccessfulAtomicBatch() {
createFundedAccount(delegatingAccount),
getAliasedAccountInfo(delegatingAccount).hasNoDelegation(),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(delegatingAccount)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -134,7 +133,7 @@ final Stream<DynamicTest> testDelegationSurvivesAtomicBatchRollback() {
createFundedAccount(delegatingAccount),
getAliasedAccountInfo(delegatingAccount).hasNoDelegation(),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(delegatingAccount)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -191,7 +190,7 @@ final Stream<DynamicTest> testNoDelegationWhenBatchFailsBeforeType4TxDispatched(
.between(INSUFFICIENT_BALANCE_ACCOUNT, RELAYER))
.hasKnownStatus(INSUFFICIENT_ACCOUNT_BALANCE)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(delegatingAccount)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -216,7 +215,7 @@ final Stream<DynamicTest> testAtomicBatchCryptoCreateThenType4DelegatesInSameBat
.withMatchingEvmAddress()
.balance(ONE_HUNDRED_HBARS)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(accountInBatch)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -243,7 +242,7 @@ final Stream<DynamicTest> testAtomicBatchCryptoCreateAndType4DelegateRolledBackO
.withMatchingEvmAddress()
.balance(ONE_HUNDRED_HBARS)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(delegatingAccount)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -280,7 +279,7 @@ final Stream<DynamicTest> testAtomicBatchCryptoCreateSetsDelegationThenType4Upda
.balance(ONE_HUNDRED_HBARS)
.delegationAddress(initialDelegationAddress)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(accountInBatch)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -303,7 +302,7 @@ final Stream<DynamicTest> testExistingAccountDelegationSurvivesRollback() {
createFundedAccount(authorityAccount),
getAliasedAccountInfo(authorityAccount).hasNoDelegation(),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -336,7 +335,7 @@ final Stream<DynamicTest> testExistingDelegationUpdatedByType4SurvivesRollback()
createFundedAccountWithDelegation(authorityAccount, delegationTargetAddress),
getAliasedAccountInfo(authorityAccount).hasDelegationAddress(delegationTargetAddress),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -369,7 +368,7 @@ final Stream<DynamicTest> testDelegationClearedByZeroAddress() {
createFundedAccountWithDelegation(authorityAccount, delegationTargetAddress),
getAliasedAccountInfo(authorityAccount).hasDelegationAddress(delegationTargetAddress),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -397,7 +396,7 @@ final Stream<DynamicTest> testDelegationClearedByZeroAddressSurvivesRollback() {
createFundedAccountWithDelegation(authorityAccount, delegationTargetAddress),
getAliasedAccountInfo(authorityAccount).hasDelegationAddress(delegationTargetAddress),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -437,7 +436,7 @@ final Stream<DynamicTest> testAtomicBatchType4PartialCommitAcrossAccountsWithInv
cryptoUpdate(CRYPTO_CREATE_DELEGATING_ACCOUNT)
.delegationAddress(delegationAddress)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -480,7 +479,7 @@ final Stream<DynamicTest> testAtomicBatchType4PartialCommitIsRolledBackOnInnerTx
cryptoUpdate(CRYPTO_CREATE_DELEGATING_ACCOUNT)
.delegationAddress(initialDelegationAddress)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -537,7 +536,7 @@ final Stream<DynamicTest> testAtomicBatchType4NoncesOnSuccess() {
getAliasedAccountInfo(sender).exposingEthereumNonceTo(senderNonceBefore::set),
getAliasedAccountInfo(authAccount1).exposingEthereumNonceTo(auth1NonceBefore::set),
getAliasedAccountInfo(authAccount2).exposingEthereumNonceTo(auth2NonceBefore::set),
atomicBatch(ethereumCall(CONTRACT, "create")
atomicBatch(ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -590,7 +589,7 @@ final Stream<DynamicTest> testAtomicBatchType4NoncesOnRollback() {
getAliasedAccountInfo(authAccount1).exposingEthereumNonceTo(auth1NonceBefore::set),
getAliasedAccountInfo(authAccount2).exposingEthereumNonceTo(auth2NonceBefore::set),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -656,7 +655,7 @@ final Stream<DynamicTest> testTx4GasChargesOnSuccessfulBatch() {
createFundedAccount(sender),
getAccountBalance(sender).exposingBalanceTo(senderBalanceBefore::set),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(sender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -685,10 +684,6 @@ final Stream<DynamicTest> testTx4GasChargesOnSuccessfulBatch() {
final var expectedGasCharge = gasUsed * gasPriceTinybars;
final var senderDelta = senderBalanceBefore.get() - senderBalanceAfter.get();

// gasUsed must exceed intrinsic gas (execution of create() costs extra)
assertTrue(
gasUsed > EXPECTED_INTRINSIC_GAS,
"gasUsed must exceed intrinsic gas (create() deploys a contract)");
// Sender pays exactly gasUsed * gasPrice (EVM gas)
assertEquals(expectedGasCharge, senderDelta, "Sender must be charged gasUsed * gasPriceTinybars");
// The type4 fee in the record should match the sender's balance change
Expand Down Expand Up @@ -718,7 +713,7 @@ final Stream<DynamicTest> testSenderGasChargesSameOnSuccessAndRollback() {
// Rollback
getAccountBalance(rollbackSender).exposingBalanceTo(rollbackSenderBefore::set),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(rollbackSender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -737,7 +732,7 @@ final Stream<DynamicTest> testSenderGasChargesSameOnSuccessAndRollback() {
// Success
getAccountBalance(successSender).exposingBalanceTo(successSenderBefore::set),
atomicBatch(
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(successSender)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -828,7 +823,7 @@ final Stream<DynamicTest> testGasAndFeesChargedOnRollbackWithCryptoCreate() {
.withMatchingEvmAddress()
.balance(ONE_HUNDRED_HBARS)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(rollbackPayer)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand All @@ -851,7 +846,7 @@ final Stream<DynamicTest> testGasAndFeesChargedOnRollbackWithCryptoCreate() {
.withMatchingEvmAddress()
.balance(ONE_HUNDRED_HBARS)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(payer)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down Expand Up @@ -942,7 +937,7 @@ final Stream<DynamicTest> testAtomicBatchRevertsAllDelegationTransactionsOnInner
cryptoUpdate(CRYPTO_CREATE_DELEGATING_ACCOUNT)
.delegationAddress(initialDelegationAddress)
.batchKey(RELAYER),
ethereumCall(CONTRACT, "create")
ethereumCall(CONTRACT, "pick")
.signingWith(delegatingAccount)
.payingWith(RELAYER)
.type(EthTransactionType.EIP7702)
Expand Down
Loading