Skip to content

Commit a3b7bb6

Browse files
authored
feat: no shard realm encoding in long zero (hiero-ledger#19349)
Signed-off-by: Luke Lee <luke.lee@hashgraph.com>
1 parent 6c380c2 commit a3b7bb6

File tree

110 files changed

+709
-666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+709
-666
lines changed

hedera-node/hapi-utils/src/main/java/com/hedera/node/app/hapi/utils/CommonUtils.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import static java.util.Objects.requireNonNull;
99

1010
import com.google.common.annotations.VisibleForTesting;
11-
import com.google.common.primitives.Ints;
1211
import com.google.common.primitives.Longs;
1312
import com.google.protobuf.ByteString;
1413
import com.google.protobuf.InvalidProtocolBufferException;
@@ -140,15 +139,11 @@ public static HederaFunctionality functionOf(@NonNull final TransactionBody txn)
140139
/**
141140
* get the EVM address from the long number.
142141
*
143-
* @param shard the shard number
144-
* @param realm the realm number
145142
* @param num the input long number
146143
* @return evm address
147144
*/
148-
public static byte[] asEvmAddress(final long shard, final long realm, final long num) {
145+
public static byte[] asEvmAddress(final long num) {
149146
final byte[] evmAddress = new byte[20];
150-
arraycopy(Ints.toByteArray((int) shard), 0, evmAddress, 0, 4);
151-
arraycopy(Longs.toByteArray(realm), 0, evmAddress, 4, 8);
152147
arraycopy(Longs.toByteArray(num), 0, evmAddress, 12, 8);
153148
return evmAddress;
154149
}

hedera-node/hapi-utils/src/test/java/com/hedera/node/app/hapi/utils/CommonUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ private Method getSetter(final B builder, final Class type) {
308308
@Test
309309
void getExpectEvmAddress() {
310310
final var address = new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123};
311-
final var evmAddress = asEvmAddress(0, 0, 123L);
311+
final var evmAddress = asEvmAddress(123L);
312312
assertArrayEquals(address, evmAddress);
313313
}
314314
}

hedera-node/hedera-app/src/main/java/com/hedera/node/app/throttle/ThrottleAccumulator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ private boolean referencesAliasNotInUse(
765765
@NonNull final AccountID idOrAlias, @NonNull final ReadableAccountStore accountStore) {
766766
if (isAlias(idOrAlias)) {
767767
final var alias = idOrAlias.aliasOrElse(Bytes.EMPTY);
768-
if (isOfEvmAddressSize(alias) && isEntityNumAlias(alias, idOrAlias.shardNum(), idOrAlias.realmNum())) {
768+
if (isOfEvmAddressSize(alias) && isEntityNumAlias(alias)) {
769769
return false;
770770
}
771771
return accountStore.getAccountIDByAlias(idOrAlias.shardNum(), idOrAlias.realmNum(), alias) == null;

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/FrameRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private record RecipientMetadata(boolean isPendingCreation, @NonNull ContractID
121121

122122
private RecipientMetadata computeRecipientMetadata(
123123
@NonNull final MessageFrame frame, @NonNull final Address address) {
124-
if (isLongZero(entityIdFactory, address)) {
124+
if (isLongZero(address)) {
125125
return new RecipientMetadata(false, asNumberedContractId(entityIdFactory, address));
126126
} else {
127127
final var updater = proxyUpdaterFor(frame);

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/operations/CustomCallOperation.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import static com.hedera.node.app.service.contract.impl.exec.failure.CustomExceptionalHaltReason.INVALID_SOLIDITY_ADDRESS;
55
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.contractRequired;
6-
import static com.hedera.node.app.service.contract.impl.exec.utils.FrameUtils.entityIdFactory;
76
import static com.hedera.node.app.service.contract.impl.utils.ConversionUtils.isLongZero;
87

98
import com.hedera.hapi.node.base.AccountID;
@@ -85,7 +84,7 @@ private boolean mustBePresent(@NonNull final MessageFrame frame, @NonNull final
8584
}
8685

8786
private boolean impliesLazyCreation(@NonNull final MessageFrame frame, @NonNull final Address toAddress) {
88-
return !isLongZero(entityIdFactory(frame), toAddress)
87+
return !isLongZero(toAddress)
8988
&& value(frame).greaterThan(Wei.ZERO)
9089
&& !addressChecks.isPresent(toAddress, frame);
9190
}

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/HasCallAttempt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected HasCallAttempt self() {
9494
*/
9595
public @Nullable Account linkedAccount(@NonNull final Address accountAddress) {
9696
requireNonNull(accountAddress);
97-
if (isLongZero(enhancement().nativeOperations().entityIdFactory(), accountAddress)) {
97+
if (isLongZero(accountAddress)) {
9898
return enhancement()
9999
.nativeOperations()
100100
.getAccount(nativeOperations()

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/getevmaddressalias/EvmAddressAliasCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public EvmAddressAliasCall(@NonNull final HasCallAttempt attempt, final Address
4242
final var explicitAddress = explicitFromHeadlong(address);
4343

4444
// If the address is not a long zero then return fail
45-
if (!isLongZero(enhancement.nativeOperations().entityIdFactory(), address)) {
45+
if (!isLongZero(address)) {
4646
return gasOnly(fullResultsFor(INVALID_ACCOUNT_ID, ZERO_ADDRESS), INVALID_ACCOUNT_ID, true);
4747
}
4848

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/hederaaccountnumalias/HederaAccountNumAliasCall.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ public HederaAccountNumAliasCall(@NonNull final HasCallAttempt attempt, @NonNull
5454
if (!account.accountIdOrElse(AccountID.DEFAULT).hasAccountNum()) {
5555
return gasOnly(fullResultsFor(INVALID_SOLIDITY_ADDRESS, ZERO_ADDRESS), INVALID_SOLIDITY_ADDRESS, true);
5656
}
57-
final var accountAsAddress = asHeadlongAddress(asEvmAddress(
58-
enhancement.nativeOperations().entityIdFactory(),
59-
account.accountIdOrElse(AccountID.DEFAULT).accountNumOrElse(0L)));
57+
final var accountAsAddress = asHeadlongAddress(
58+
asEvmAddress(account.accountIdOrElse(AccountID.DEFAULT).accountNumOrElse(0L)));
6059
return gasOnly(fullResultsFor(SUCCESS, accountAsAddress), SUCCESS, true);
6160
}
6261

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isauthorizedraw/IsAuthorizedRawCall.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ public PricedResult execute(@NonNull final MessageFrame frame) {
9494
switch (signatureType) {
9595
case EC -> customGasCalculator.getEcrecPrecompiledContractGasCost();
9696
case ED -> customGasCalculator.getEdSignatureVerificationSystemContractGasCost();
97-
case INVALID -> Math.min(
98-
customGasCalculator.getEcrecPrecompiledContractGasCost(),
99-
customGasCalculator.getEdSignatureVerificationSystemContractGasCost());
97+
case INVALID ->
98+
Math.min(
99+
customGasCalculator.getEcrecPrecompiledContractGasCost(),
100+
customGasCalculator.getEdSignatureVerificationSystemContractGasCost());
100101
};
101102

102103
// Prepare the short-circuit error status returns
@@ -271,7 +272,7 @@ public boolean isValidAccount(final long accountNum, @NonNull final SignatureTyp
271272
// If the signature is for an ecdsa key, the HIP states that the account must have an evm address rather than a
272273
// long zero address
273274
if (signatureType == SignatureType.EC) {
274-
return !isLongZero(enhancement.nativeOperations().entityIdFactory(), address);
275+
return !isLongZero(address);
275276
}
276277

277278
return true;

hedera-node/hedera-smart-contract-service-impl/src/main/java/com/hedera/node/app/service/contract/impl/exec/systemcontracts/has/isvalidalias/IsValidAliasCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public enum AliasKind {
6363
*/
6464
public static @NonNull AliasKind getAliasKindForAddressWithAccount(
6565
@NonNull final Address address, @NonNull final HederaNativeOperations nativeOperations) {
66-
final boolean isAccountNumAlias /*aka long-zero*/ = isLongZero(nativeOperations.entityIdFactory(), address);
66+
final boolean isAccountNumAlias /*aka long-zero*/ = isLongZero(address);
6767
final long accountNum = accountNumberForEvmReference(address, nativeOperations);
6868

6969
if (accountNum == MISSING_ENTITY_NUMBER) {

0 commit comments

Comments
 (0)