Skip to content
Closed
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
10 changes: 3 additions & 7 deletions actuator/src/main/java/org/tron/core/utils/TransactionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.tron.api.GrpcAPI.TransactionExtention;
import org.tron.api.GrpcAPI.TransactionSignWeight;
import org.tron.api.GrpcAPI.TransactionSignWeight.Result;
import org.tron.common.parameter.CommonParameter;
import org.tron.common.utils.Sha256Hash;
import org.tron.core.ChainBaseManager;
import org.tron.core.capsule.AccountCapsule;
Expand Down Expand Up @@ -117,8 +116,7 @@ private static boolean validReadableBytes(byte[] bytes, int maxLength) {
}

public static Sha256Hash getTransactionId(Transaction transaction) {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
transaction.getRawData().toByteArray());
return Sha256Hash.of(transaction.getRawData().toByteArray());
}


Expand Down Expand Up @@ -187,8 +185,7 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
TransactionSignWeight.Builder tswBuilder = TransactionSignWeight.newBuilder();
TransactionExtention.Builder trxExBuilder = TransactionExtention.newBuilder();
trxExBuilder.setTransaction(trx);
trxExBuilder.setTxid(ByteString.copyFrom(Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), trx.getRawData().toByteArray())));
trxExBuilder.setTxid(ByteString.copyFrom(Sha256Hash.hash(trx.getRawData().toByteArray())));
Return.Builder retBuilder = Return.newBuilder();
retBuilder.setResult(true).setCode(response_code.SUCCESS);
trxExBuilder.setResult(retBuilder);
Expand Down Expand Up @@ -224,8 +221,7 @@ public TransactionSignWeight getTransactionSignWeight(Transaction trx) {
if (trx.getSignatureCount() > 0) {
List<ByteString> approveList = new ArrayList<>();
long currentWeight = TransactionCapsule.checkWeight(permission, trx.getSignatureList(),
Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), trx.getRawData().toByteArray()), approveList);
Sha256Hash.hash(trx.getRawData().toByteArray()), approveList);
tswBuilder.addAllApprovedList(approveList);
tswBuilder.setCurrentWeight(currentWeight);
}
Expand Down
27 changes: 9 additions & 18 deletions actuator/src/main/java/org/tron/core/vm/PrecompiledContracts.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,9 @@ private static byte[] recoverAddrBySign(byte[] sign, byte[] hash) {
}
try {
Rsv rsv = Rsv.fromSignature(sign);
SignatureInterface signature = SignUtils.fromComponents(rsv.getR(), rsv.getS(), rsv.getV(),
CommonParameter.getInstance().isECKeyCryptoEngine());
SignatureInterface signature = SignUtils.fromComponents(rsv.getR(), rsv.getS(), rsv.getV());
if (signature.validateComponents()) {
out = SignUtils.signatureToAddress(hash, signature,
CommonParameter.getInstance().isECKeyCryptoEngine());
out = SignUtils.signatureToAddress(hash, signature);
}
} catch (Throwable any) {
logger.info("ECRecover error", any.getMessage());
Expand Down Expand Up @@ -518,11 +516,9 @@ public long getEnergyForData(byte[] data) {
public Pair<Boolean, byte[]> execute(byte[] data) {

if (data == null) {
return Pair.of(true, Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), EMPTY_BYTE_ARRAY));
return Pair.of(true, Sha256Hash.hash(EMPTY_BYTE_ARRAY));
}
return Pair.of(true, Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), data));
return Pair.of(true, Sha256Hash.hash(data));
}
}

Expand All @@ -548,11 +544,9 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
data = EMPTY_BYTE_ARRAY;
}

byte[] orig = Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), data);
byte[] orig = Sha256Hash.hash(data);
System.arraycopy(orig, 0, target, 0, 20);
return Pair.of(true, Sha256Hash.hash(CommonParameter.getInstance()
.isECKeyCryptoEngine(), target));
return Pair.of(true, Sha256Hash.hash(target));
}
}

Expand Down Expand Up @@ -590,11 +584,9 @@ public Pair<Boolean, byte[]> execute(byte[] data) {
int sLength = data.length < 128 ? data.length - 96 : 32;
System.arraycopy(data, 96, s, 0, sLength);

SignatureInterface signature = SignUtils.fromComponents(r, s, v[31]
, CommonParameter.getInstance().isECKeyCryptoEngine());
SignatureInterface signature = SignUtils.fromComponents(r, s, v[31]);
if (validateV(v) && signature.validateComponents()) {
out = new DataWord(SignUtils.signatureToAddress(h, signature
, CommonParameter.getInstance().isECKeyCryptoEngine()));
out = new DataWord(SignUtils.signatureToAddress(h, signature));
}
} catch (Throwable any) {
}
Expand Down Expand Up @@ -948,8 +940,7 @@ public Pair<Boolean, byte[]> execute(byte[] rawData) {
byte[] data = words[2].getData();

byte[] combine = ByteUtil.merge(address, ByteArray.fromInt(permissionId), data);
byte[] hash = Sha256Hash.hash(CommonParameter
.getInstance().isECKeyCryptoEngine(), combine);
byte[] hash = Sha256Hash.hash(combine);

if (VMConfig.allowTvmSelfdestructRestriction()) {
int sigArraySize = words[words[3].intValueSafe() / WORD_SIZE].intValueSafe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public DataWord getBalance() {
public DataWord getOriginAddress() {

byte[] cowPrivKey = Hash.sha3("horse".getBytes());
byte[] addr = SignUtils.fromPrivate(cowPrivKey
, CommonParameter.getInstance().isECKeyCryptoEngine()).getAddress();
byte[] addr = SignUtils.fromPrivate(cowPrivKey).getAddress();

return new DataWord(addr);
}
Expand All @@ -89,8 +88,7 @@ public DataWord getOriginAddress() {
public DataWord getCallerAddress() {

byte[] cowPrivKey = Hash.sha3("monkey".getBytes());
byte[] addr = SignUtils.fromPrivate(cowPrivKey
, CommonParameter.getInstance().isECKeyCryptoEngine()).getAddress();
byte[] addr = SignUtils.fromPrivate(cowPrivKey).getAddress();
return new DataWord(addr);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public byte[] getSendBytes() {
}

public Sha256Hash getMessageId() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
getData());
return Sha256Hash.of(getData());
}

public byte[] getData() {
Expand Down Expand Up @@ -110,4 +109,4 @@ public boolean equals(Object o) {
return Arrays.equals(data, message.data);
}

}
}
7 changes: 2 additions & 5 deletions chainbase/src/main/java/org/tron/common/utils/Commons.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.tron.common.parameter.CommonParameter;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.capsule.ExchangeCapsule;
import org.tron.core.exception.BalanceInsufficientException;
Expand All @@ -28,10 +27,8 @@ public static byte[] decode58Check(String input) {
}
byte[] decodeData = new byte[decodeCheck.length - 4];
System.arraycopy(decodeCheck, 0, decodeData, 0, decodeData.length);
byte[] hash0 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(),
decodeData);
byte[] hash1 = Sha256Hash.hash(CommonParameter.getInstance().isECKeyCryptoEngine(),
hash0);
byte[] hash0 = Sha256Hash.hash(decodeData);
byte[] hash1 = Sha256Hash.hash(hash0);
if (hash1[0] == decodeCheck[decodeData.length] &&
hash1[1] == decodeCheck[decodeData.length + 1] &&
hash1[2] == decodeCheck[decodeData.length + 2] &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ public LocalWitnesses(List<String> privateKeys) {
setPrivateKeys(privateKeys);
}

public void initWitnessAccountAddress(final byte[] witnessAddress,
boolean isECKeyCryptoEngine) {
public void initWitnessAccountAddress(final byte[] witnessAddress) {
if (witnessAddress != null) {
this.witnessAccountAddress = witnessAddress;
} else if (!CollectionUtils.isEmpty(privateKeys)) {
byte[] privateKey = ByteArray.fromHexString(getPrivateKey());
final SignInterface ecKey = SignUtils.fromPrivate(privateKey,
isECKeyCryptoEngine);
final SignInterface ecKey = SignUtils.fromPrivate(privateKey);
this.witnessAccountAddress = ecKey.getAddress();
}
}
Expand Down
11 changes: 4 additions & 7 deletions chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ private void initTxs() {

// TODO add unit test for sig2.getbytes
public void sign(byte[] privateKey) {
SignInterface ecKeyEngine = SignUtils
.fromPrivate(privateKey, CommonParameter.getInstance().isECKeyCryptoEngine());
SignInterface ecKeyEngine = SignUtils.fromPrivate(privateKey);

ByteString sig = ByteString.copyFrom(ecKeyEngine.Base64toBytes(ecKeyEngine.signHash(getRawHash()
.getBytes())));
Expand All @@ -174,17 +173,15 @@ public void sign(byte[] privateKey) {
}

private Sha256Hash getRawHash() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
this.block.getBlockHeader().getRawData().toByteArray());
return Sha256Hash.of(this.block.getBlockHeader().getRawData().toByteArray());
}

public boolean validateSignature(DynamicPropertiesStore dynamicPropertiesStore,
AccountStore accountStore) throws ValidateSignatureException {
try {
byte[] sigAddress = SignUtils.signatureToAddress(getRawHash().getBytes(),
TransactionCapsule.getBase64FromByteString(
block.getBlockHeader().getWitnessSignature()),
CommonParameter.getInstance().isECKeyCryptoEngine());
block.getBlockHeader().getWitnessSignature()));
byte[] witnessAccountAddress = block.getBlockHeader().getRawData().getWitnessAddress()
.toByteArray();

Expand All @@ -204,7 +201,7 @@ public boolean validateSignature(DynamicPropertiesStore dynamicPropertiesStore,
public BlockId getBlockId() {
if (blockId.equals(Sha256Hash.ZERO_HASH)) {
blockId =
new BlockId(Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
new BlockId(Sha256Hash.of(
this.block.getBlockHeader().getRawData().toByteArray()), getNum());
}
return blockId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public CodeCapsule(byte[] code) {
}

public Sha256Hash getCodeHash() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
this.code);
return Sha256Hash.of(this.code);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ private void markDirty() {
}

public Sha256Hash getHash() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
this.rowValue);
return Sha256Hash.of(this.rowValue);
}

public byte[] getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public class TransactionCapsule implements ProtoCapsule<Transaction> {

private static final String esName = "valid-contract-proto";
private static final ExecutorService executorService = ExecutorServiceManager
.newFixedThreadPool(esName, CommonParameter.getInstance()
.getValidContractProtoThreadNum());
.newFixedThreadPool(esName,
CommonParameter.getInstance().getValidContractProtoThreadNum());
private static final String OWNER_ADDRESS = "ownerAddress_";

private Transaction transaction;
Expand Down Expand Up @@ -242,8 +242,7 @@ public static long checkWeight(Permission permission, List<ByteString> sigs, byt
"Signature size is " + sig.size());
}
String base64 = TransactionCapsule.getBase64FromByteString(sig);
byte[] address = SignUtils
.signatureToAddress(hash, base64, CommonParameter.getInstance().isECKeyCryptoEngine());
byte[] address = SignUtils.signatureToAddress(hash, base64);
long weight = getWeight(permission, address);
if (weight == 0) {
throw new PermissionException(
Expand Down Expand Up @@ -311,11 +310,10 @@ public static byte[] hashShieldTransaction(Transaction tx, String tokenId)
Transaction transaction = tx.toBuilder().clearRawData()
.setRawData(rawBuilder).build();

byte[] mergedByte = Bytes.concat(Sha256Hash
.of(CommonParameter.getInstance().isECKeyCryptoEngine(), tokenId.getBytes()).getBytes(),
byte[] mergedByte = Bytes.concat(
Sha256Hash.of(tokenId.getBytes()).getBytes(),
transaction.getRawData().toByteArray());
return Sha256Hash.of(CommonParameter
.getInstance().isECKeyCryptoEngine(), mergedByte).getBytes();
return Sha256Hash.of(mergedByte).getBytes();
}

// todo mv this static function to capsule util
Expand Down Expand Up @@ -563,18 +561,15 @@ public void createTransaction(com.google.protobuf.Message message, ContractType

public Sha256Hash getMerkleHash() {
byte[] transBytes = this.transaction.toByteArray();
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
transBytes);
return Sha256Hash.of(transBytes);
}

private Sha256Hash getRawHash() {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
this.transaction.getRawData().toByteArray());
return Sha256Hash.of(this.transaction.getRawData().toByteArray());
}

public void sign(byte[] privateKey) {
SignInterface cryptoEngine = SignUtils
.fromPrivate(privateKey, CommonParameter.getInstance().isECKeyCryptoEngine());
SignInterface cryptoEngine = SignUtils.fromPrivate(privateKey);
ByteString sig = ByteString.copyFrom(cryptoEngine.Base64toBytes(cryptoEngine
.signHash(getTransactionId().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
Expand All @@ -595,8 +590,7 @@ public void addSign(byte[] privateKey, AccountStore accountStore)
}
checkPermission(permissionId, permission, contract);
List<ByteString> approveList = new ArrayList<>();
SignInterface cryptoEngine = SignUtils
.fromPrivate(privateKey, CommonParameter.getInstance().isECKeyCryptoEngine());
SignInterface cryptoEngine = SignUtils.fromPrivate(privateKey);
byte[] address = cryptoEngine.getAddress();
if (this.transaction.getSignatureCount() > 0) {
checkWeight(permission, this.transaction.getSignatureList(),
Expand All @@ -617,7 +611,7 @@ public void addSign(byte[] privateKey, AccountStore accountStore)
.signHash(getTransactionId().getBytes())));
this.transaction = this.transaction.toBuilder().addSignature(sig).build();
}

private static void checkPermission(int permissionId, Permission permission, Transaction.Contract contract) throws PermissionException {
if (permissionId != 0) {
if (permission.getType() != PermissionType.Active) {
Expand Down Expand Up @@ -684,7 +678,7 @@ public boolean validateSignature(AccountStore accountStore,
}
}
isVerified = true;
}
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private Leaf createLeaf(Sha256Hash hash) {
}

private Sha256Hash computeHash(Sha256Hash leftHash, Sha256Hash rightHash) {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
return Sha256Hash.of(
leftHash.getByteString().concat(rightHash.getByteString()).toByteArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ private void calcMerkleRoot() {
}

private Sha256Hash getHash(Map.Entry<byte[], byte[]> entry) {
return Sha256Hash.of(CommonParameter.getInstance().isECKeyCryptoEngine(),
Bytes.concat(entry.getKey(), entry.getValue()));
return Sha256Hash.of(Bytes.concat(entry.getKey(), entry.getValue()));
}

private void startRewardCal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,6 @@ public class CommonParameter {
public EventPluginConfig eventPluginConfig;
@Getter
public FilterQuery eventFilter;
@Getter
@Setter
public String cryptoEngine = Constant.ECKey_ENGINE;

@Getter
@Setter
public boolean rpcEnable = true;
Expand Down Expand Up @@ -652,10 +648,6 @@ public static void reset() {
PARAMETER = new CommonParameter();
}

public boolean isECKeyCryptoEngine() {
return cryptoEngine.equalsIgnoreCase(Constant.ECKey_ENGINE);
}

public boolean isJsonRpcFilterEnabled() {
return jsonRpcHttpFullNodeEnable
|| jsonRpcHttpSolidityNodeEnable;
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/tron/common/utils/MerkleRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static Leaf createLeaf(Sha256Hash hash) {
}

private static Sha256Hash computeHash(Sha256Hash leftHash, Sha256Hash rightHash) {
return Sha256Hash.of(true,
return Sha256Hash.of(
leftHash.getByteString().concat(rightHash.getByteString()).toByteArray());
}

Expand Down
Loading
Loading