Skip to content

Commit 5a94004

Browse files
committed
Merge branch 'release_v4.8.2' into feature/config_comment
2 parents 0019bb7 + c8ba119 commit 5a94004

38 files changed

Lines changed: 605 additions & 1292 deletions

common/src/main/java/org/tron/core/Constant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public class Constant {
1919
public static final long MAXIMUM_TIME_UNTIL_EXPIRATION = 24 * 60 * 60 * 1_000L; //one day
2020
public static final long TRANSACTION_DEFAULT_EXPIRATION_TIME = 60 * 1_000L; //60 seconds
2121
public static final long TRANSACTION_FEE_POOL_PERIOD = 1; //1 blocks
22-
public static final long PER_SIGN_LENGTH = 65L;
22+
public static final int PER_SIGN_LENGTH = 65;
23+
public static final int MAX_PER_SIGN_LENGTH = 68;
2324
public static final long MAX_CONTRACT_RESULT_SIZE = 2L;
2425

2526
// Smart contract / Energy

crypto/src/main/java/org/tron/common/crypto/SignUtils.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.tron.common.crypto;
22

3+
import static org.tron.core.Constant.MAX_PER_SIGN_LENGTH;
4+
import static org.tron.core.Constant.PER_SIGN_LENGTH;
5+
36
import java.security.SecureRandom;
47
import java.security.SignatureException;
58
import org.tron.common.crypto.ECKey.ECDSASignature;
@@ -8,6 +11,21 @@
811

912
public class SignUtils {
1013

14+
/**
15+
* Strict signature-length check for admission entry-points (RPC broadcast,
16+
* P2P transaction ingress, peer hello handshake). Accepts only sizes in
17+
* [{@link org.tron.core.Constant#PER_SIGN_LENGTH PER_SIGN_LENGTH},
18+
* {@link org.tron.core.Constant#MAX_PER_SIGN_LENGTH MAX_PER_SIGN_LENGTH}].
19+
*
20+
* <p>Consensus paths (e.g. {@code TransactionCapsule.checkWeight}) intentionally
21+
* keep the looser {@code size < 65} check to remain compatible with historical
22+
* on-chain signatures that carry trailing padding bytes; do not call this
23+
* helper from those paths.
24+
*/
25+
public static boolean isValidLength(int size) {
26+
return size >= PER_SIGN_LENGTH && size <= MAX_PER_SIGN_LENGTH;
27+
}
28+
1129
public static SignInterface getGeneratedRandomSign(
1230
SecureRandom secureRandom, boolean isECKeyCryptoEngine) {
1331
if (isECKeyCryptoEngine) {

docs/implement-a-customized-actuator-en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public class SumActuatorTest {
229229
@BeforeClass
230230
public static void init() throws IOException {
231231
Args.setParam(new String[]{"--output-directory",
232-
temporaryFolder.newFolder().toString()}, "config-localtest.conf");
232+
temporaryFolder.newFolder().toString()}, "config-test.conf");
233233
context = new TronApplicationContext(DefaultConfig.class);
234234
appTest = ApplicationFactory.create(context);
235235
appTest.startup();
@@ -255,7 +255,7 @@ public class SumActuatorTest {
255255

256256
@Test
257257
public void sumActuatorTest() {
258-
// this key is defined in config-localtest.conf as accountName=Sun
258+
// this key is defined in config-test.conf as accountName=Sun
259259
String key = "<your_private_key>";
260260
byte[] address = PublicMethed.getFinalAddress(key);
261261
ECKey ecKey = null;

docs/implement-a-customized-actuator-zh.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public class SumActuatorTest {
231231
@BeforeClass
232232
public static void init() throws IOException {
233233
Args.setParam(new String[]{"--output-directory",
234-
temporaryFolder.newFolder().toString()}, "config-localtest.conf");
234+
temporaryFolder.newFolder().toString()}, "config-test.conf");
235235
context = new TronApplicationContext(DefaultConfig.class);
236236
appTest = ApplicationFactory.create(context);
237237
appTest.startup();
@@ -257,7 +257,7 @@ public class SumActuatorTest {
257257

258258
@Test
259259
public void sumActuatorTest() {
260-
// this key is defined in config-localtest.conf as accountName=Sun
260+
// this key is defined in config-test.conf as accountName=Sun
261261
String key = "<your_private_key>";
262262
byte[] address = PublicMethed.getFinalAddress(key);
263263
ECKey ecKey = null;

framework/src/main/java/org/tron/core/Wallet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,16 @@ public GrpcAPI.Return broadcastTransaction(Transaction signedTransaction) {
505505
trx.setTime(System.currentTimeMillis());
506506
Sha256Hash txID = trx.getTransactionId();
507507
try {
508+
for (ByteString sig : signedTransaction.getSignatureList()) {
509+
if (!SignUtils.isValidLength(sig.size())) {
510+
String info = "Signature size is " + sig.size();
511+
logger.warn("Broadcast transaction {} has failed, {}.", txID, info);
512+
return builder.setResult(false).setCode(response_code.SIGERROR)
513+
.setMessage(ByteString.copyFromUtf8("Validate signature error: " + info))
514+
.build();
515+
}
516+
}
517+
508518
if (tronNetDelegate.isBlockUnsolidified()) {
509519
logger.warn("Broadcast transaction {} has failed, block unsolidified.", txID);
510520
return builder.setResult(false).setCode(response_code.BLOCK_UNSOLIDIFIED)

framework/src/main/java/org/tron/core/net/messagehandler/TransactionsMsgHandler.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.tron.core.net.messagehandler;
22

3+
import com.google.protobuf.ByteString;
34
import java.util.HashSet;
45
import java.util.List;
56
import java.util.Set;
@@ -13,6 +14,7 @@
1314
import lombok.extern.slf4j.Slf4j;
1415
import org.springframework.beans.factory.annotation.Autowired;
1516
import org.springframework.stereotype.Component;
17+
import org.tron.common.crypto.SignUtils;
1618
import org.tron.common.es.ExecutorServiceManager;
1719
import org.tron.common.utils.Sha256Hash;
1820
import org.tron.core.ChainBaseManager;
@@ -142,6 +144,12 @@ private void check(PeerConnection peer, TransactionsMessage msg) throws P2pExcep
142144
throw new P2pException(TypeEnum.BAD_TRX,
143145
"tx " + item.getHash() + " contract size should be greater than 0");
144146
}
147+
for (ByteString sig : trx.getSignatureList()) {
148+
if (!SignUtils.isValidLength(sig.size())) {
149+
throw new P2pException(TypeEnum.BAD_TRX,
150+
"tx " + item.getHash() + " signature size is " + sig.size());
151+
}
152+
}
145153
}
146154
}
147155

framework/src/main/java/org/tron/core/net/service/relay/RelayService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ public boolean checkHelloMessage(HelloMessage message, Channel channel) {
150150
return false;
151151
}
152152

153+
if (!SignUtils.isValidLength(msg.getSignature().size())) {
154+
logger.warn("HelloMessage from {}, signature size is {}.",
155+
channel.getInetAddress(), msg.getSignature().size());
156+
return false;
157+
}
158+
153159
boolean flag;
154160
try {
155161
Sha256Hash hash = Sha256Hash.of(CommonParameter

framework/src/main/java/org/tron/program/SolidityNode.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,15 @@ private void getBlock() {
117117
Block block = getBlockByNum(blockNum);
118118
blockQueue.put(block);
119119
blockNum = ID.incrementAndGet();
120+
} catch (InterruptedException e) {
121+
Thread.currentThread().interrupt();
122+
logger.info("getBlock interrupted, exiting.");
123+
return;
120124
} catch (Exception e) {
125+
if (!flag) {
126+
logger.info("getBlock stopped during shutdown, last block: {}.", blockNum);
127+
return;
128+
}
121129
logger.error("Failed to get block {}, reason: {}.", blockNum, e.getMessage());
122130
sleep(exceptionSleepTime);
123131
}
@@ -194,6 +202,10 @@ private long getLastSolidityBlockNum() {
194202
blockNum, remoteBlockNum, System.currentTimeMillis() - time);
195203
return blockNum;
196204
} catch (Exception e) {
205+
if (!flag) {
206+
logger.info("getLastSolidityBlockNum stopped during shutdown.");
207+
return 0;
208+
}
197209
logger.error("Failed to get last solid blockNum: {}, reason: {}.", remoteBlockNum.get(),
198210
e.getMessage());
199211
sleep(exceptionSleepTime);
@@ -205,8 +217,8 @@ private long getLastSolidityBlockNum() {
205217
public void sleep(long time) {
206218
try {
207219
Thread.sleep(time);
208-
} catch (Exception e1) {
209-
logger.error(e1.getMessage());
220+
} catch (InterruptedException e) {
221+
Thread.currentThread().interrupt();
210222
}
211223
}
212224

framework/src/test/java/org/tron/common/TestConstants.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@
2323
public class TestConstants {
2424

2525
public static final String TEST_CONF = "config-test.conf";
26-
public static final String NET_CONF = "config.conf";
27-
public static final String MAINNET_CONF = "config-test-mainnet.conf";
28-
public static final String LOCAL_CONF = "config-localtest.conf";
29-
public static final String STORAGE_CONF = "config-test-storagetest.conf";
30-
public static final String INDEX_CONF = "config-test-index.conf";
26+
public static final String SHIELD_CONF = "config-shield.conf";
3127

3228
/**
3329
* Skips the current test on ARM64 where LevelDB JNI is unavailable.

framework/src/test/java/org/tron/common/runtime/vm/BandWidthRuntimeOutOfTimeTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.Before;
2222
import org.junit.Test;
2323
import org.tron.common.BaseTest;
24+
import org.tron.common.TestConstants;
2425
import org.tron.common.runtime.RuntimeImpl;
2526
import org.tron.common.runtime.TvmTestUtils;
2627
import org.tron.common.utils.Commons;
@@ -73,7 +74,7 @@ public class BandWidthRuntimeOutOfTimeTest extends BaseTest {
7374
"--storage-db-directory", dbDirectory,
7475
"--debug"
7576
},
76-
"config-test-mainnet.conf"
77+
TestConstants.TEST_CONF
7778
);
7879
}
7980

0 commit comments

Comments
 (0)