forked from tronprotocol/java-tron
-
Notifications
You must be signed in to change notification settings - Fork 0
Pqc falcon512 #31
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
Merged
Federico2014
merged 3 commits into
Federico2014:pqc-falcon512
from
Little-Peony:pqc-falcon512
May 21, 2026
Merged
Pqc falcon512 #31
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,7 @@ | |
| import org.tron.common.utils.StringUtil; | ||
| import org.tron.common.zksnark.MerkleContainer; | ||
| import org.tron.consensus.Consensus; | ||
| import org.tron.consensus.base.Param; | ||
| import org.tron.consensus.base.Param.Miner; | ||
| import org.tron.core.ChainBaseManager; | ||
| import org.tron.core.Constant; | ||
|
|
@@ -1746,7 +1747,12 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) { | |
| session.reset(); | ||
|
|
||
| blockCapsule.setMerkleRoot(); | ||
| signBlockCapsule(blockCapsule, miner); | ||
| if (getDynamicPropertiesStore().isAnyPqSchemeAllowed() && | ||
| miner.getPqScheme() != null) { | ||
| signBlockCapsuleWithPQ(blockCapsule, miner); | ||
| } else { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里也不应该用else, 若是 pq 方案不允许,minerType 为PQ, 走ecdsa 签名就有问题。 |
||
| blockCapsule.sign(miner.getPrivateKey()); | ||
| } | ||
|
|
||
| BlockCapsule capsule = new BlockCapsule(blockCapsule.getInstance()); | ||
| capsule.generatedByMyself = true; | ||
|
|
@@ -1762,57 +1768,23 @@ public BlockCapsule generateBlock(Miner miner, long blockTime, long timeout) { | |
| return capsule; | ||
| } | ||
|
|
||
| private void signBlockCapsule(BlockCapsule blockCapsule, Miner miner) { | ||
| switch (miner.getType()) { | ||
| case PQ: | ||
| PQScheme scheme = resolveWitnessScheme(miner); | ||
| if (scheme == null) { | ||
| // PQ-only miner whose configured scheme is not currently usable | ||
| // (proposal not activated, scheme allow flag flipped, witness | ||
| // permission missing, etc.). Surface a clear cause; DposTask's | ||
| // Throwable handler will log and the witness will miss this slot, | ||
| // but the producer thread keeps running. | ||
| throw new IllegalStateException( | ||
| "PQ-only miner " + Hex.toHexString(miner.getWitnessAddress().toByteArray()) | ||
| + " has scheme " + miner.getPqScheme() | ||
| + " configured but it is not currently usable " | ||
| + "(scheme not allowed by dynamic properties, " | ||
| + "or witness permission is missing/empty)"); | ||
| } | ||
| signWitnessAuth(blockCapsule, miner, scheme); | ||
| break; | ||
| case ECDSA: | ||
| blockCapsule.sign(miner.getPrivateKey()); | ||
| break; | ||
| default: | ||
| throw new IllegalStateException("unknown miner type: " + miner.getType()); | ||
| } | ||
| } | ||
|
|
||
| private PQScheme resolveWitnessScheme(Miner miner) { | ||
| if (!chainBaseManager.getDynamicPropertiesStore().isAnyPqSchemeAllowed()) { | ||
| return null; | ||
| } | ||
| private void signBlockCapsuleWithPQ(BlockCapsule blockCapsule, Miner miner) { | ||
| PQScheme scheme = miner.getPqScheme(); | ||
| if (scheme == null || !PQSchemeRegistry.contains(scheme)) { | ||
| return null; | ||
| throw new IllegalStateException( | ||
| "PQ-only miner " + Hex.toHexString(miner.getWitnessAddress().toByteArray()) | ||
| + " has scheme " + miner.getPqScheme() | ||
| + " configured but it is not currently usable " | ||
| + "or witness permission is missing/empty)"); | ||
| } | ||
| if (!chainBaseManager.getDynamicPropertiesStore().isPqSchemeAllowed(scheme)) { | ||
| return null; | ||
| } | ||
| byte[] witnessAddress = miner.getWitnessAddress().toByteArray(); | ||
| AccountCapsule accountCapsule = chainBaseManager.getAccountStore().get(witnessAddress); | ||
| if (accountCapsule == null || !accountCapsule.getInstance().hasWitnessPermission()) { | ||
| return null; | ||
| } | ||
| Permission witnessPermission = accountCapsule.getInstance().getWitnessPermission(); | ||
| if (witnessPermission.getKeysCount() == 0) { | ||
| return null; | ||
| throw new IllegalStateException( | ||
| "PQ-only miner " + Hex.toHexString(miner.getWitnessAddress().toByteArray()) | ||
| + " has scheme " + miner.getPqScheme() | ||
| + " but it is not allowed by dynamic properties"); | ||
| } | ||
| return scheme; | ||
| } | ||
|
|
||
| private void signWitnessAuth(BlockCapsule blockCapsule, Miner miner, PQScheme scheme) { | ||
|
|
||
| byte[] pqPrivateKey = miner.getPQPrivateKey(); | ||
| byte[] pqPublicKey = miner.getPQPublicKey(); | ||
| if (pqPrivateKey == null || pqPublicKey == null) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是否允许某个PQ 方案不应该是看提案是否开启了么