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

fix: canUseAliasesInPrecompilesAndContractKeys checks EVM_ADDRESS is 20 bytes #10327

Merged
merged 3 commits into from
Dec 7, 2023
Merged
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 @@ -34,6 +34,7 @@ public class KeyUtils {

public static final Key IMMUTABILITY_SENTINEL_KEY =
Key.newBuilder().keyList(KeyList.DEFAULT).build();
public static final int EVM_ADDRESS_BYTE_LENGTH = 20;
public static final int ED25519_BYTE_LENGTH = 32;
private static final byte ODD_PARITY = (byte) 0x03;
private static final byte EVEN_PARITY = (byte) 0x02;
Expand Down Expand Up @@ -106,12 +107,9 @@ private static boolean isEmptyInternal(@Nullable final Key pbjKey, boolean honor
return ((Bytes) key.value()).length() == 0;
} else if (pbjKey.hasEcdsaSecp256k1()) {
return ((Bytes) key.value()).length() == 0;
} else if (pbjKey.hasDelegatableContractId()) {
return !((ContractID) key.value()).hasContractNum()
|| (((ContractID) key.value()).hasContractNum() && ((ContractID) key.value()).contractNum() == 0);
} else if (pbjKey.hasContractID()) {
return !((ContractID) key.value()).hasContractNum()
|| (((ContractID) key.value()).hasContractNum() && ((ContractID) key.value()).contractNum() == 0);
} else if (pbjKey.hasDelegatableContractId() || pbjKey.hasContractID()) {
return ((ContractID) key.value()).contractNumOrElse(0L) == 0
&& ((ContractID) key.value()).evmAddressOrElse(Bytes.EMPTY).length() == 0L;
}
// ECDSA_384 and RSA_3072 are not supported yet
return true;
Expand Down Expand Up @@ -152,10 +150,9 @@ public static boolean isValid(@Nullable final Key pbjKey) {
final var ecKey = ((Bytes) key.value());
return ecKey.length() == ECDSA_SECP256K1_COMPRESSED_KEY_LENGTH
&& (ecKey.getByte(0) == EVEN_PARITY || ecKey.getByte(0) == ODD_PARITY);
} else if (pbjKey.hasDelegatableContractId()) {
return ((ContractID) key.value()).contractNum().intValue() > 0;
} else if (pbjKey.hasContractID()) {
return ((ContractID) key.value()).contractNum().intValue() > 0;
} else if (pbjKey.hasDelegatableContractId() || pbjKey.hasContractID()) {
return ((ContractID) key.value()).contractNumOrElse(0L) > 0
|| ((ContractID) key.value()).evmAddressOrElse(Bytes.EMPTY).length() == EVM_ADDRESS_BYTE_LENGTH;
}
// ECDSA_384 and RSA_3072 are not supported yet
return true;
Expand Down
Loading