Skip to content

Pqc falcon512#28

Open
Federico2014 wants to merge 4 commits into
Federico2014:pqc-falcon512from
Little-Peony:pqc-falcon512
Open

Pqc falcon512#28
Federico2014 wants to merge 4 commits into
Federico2014:pqc-falcon512from
Little-Peony:pqc-falcon512

Conversation

@Federico2014
Copy link
Copy Markdown
Owner

@Federico2014 Federico2014 commented May 18, 2026

What does this PR do?

Why are these changes required?

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details


Summary by cubic

Gate Falcon-512 (FN-DSA-512) signatures behind governance activation and bundle PQ priv/pub keys into a single PqKeypair. This prevents config mistakes, tightens signature checks, and keeps legacy behavior until PQ is enabled.

  • Refactors

    • Added PqKeypair and replaced parallel PQ key lists in LocalWitnesses; Args now parses extended hex entries into pairs; updated WitnessInitializer.initFromPQOnly.
    • ConsensusService and RelayService now consume List<PqKeypair> for single/multi-witness setups.
    • BlockCapsule: PQ validation runs only when isAnyPqSchemeAllowed() is true; derived PQ public key address must equal the witness permission address; hasWitnessSignature now requires DynamicPropertiesStore.
    • Transactions: TransactionUtil.getTransactionSignWeight gates PQ checks on isAnyPqSchemeAllowed(), uses TransactionCapsule.validatePQSignatureGetWeight, and always sets approve list and current weight.
    • TransactionCapsule: renamed PQ validator to validatePQSignatureGetWeight and manages its own dedup set.
    • Call sites updated: VMActuator/Manager pass DynamicPropertiesStore; CPU limit ratio helper now takes DynamicPropertiesStore.
  • Migration

    • Replace calls to LocalWitnesses#getPqPrivateKeys()/getPqPublicKeys() with getPqKeypairs().
    • Updated APIs: WitnessInitializer.initFromPQOnly(PQScheme, List<PqKeypair>, String), BlockCapsule#hasWitnessSignature(DynamicPropertiesStore), TransactionCapsule.validatePQSignatureGetWeight(...), and VMActuator#getCpuLimitInUsRatio(DynamicPropertiesStore).
    • Behavior change: PQ-only blocks and PQ tx signatures are ignored until a PQ scheme is activated (e.g., saveAllowFnDsa512(1)), preserving pre-activation semantics.

Written for commit bd79efc. Summary will update on new commits. Review in cubic

Little-Peony and others added 4 commits May 18, 2026 12:25
The inline fully-qualified java.util.Set / HashSet in validatePQSignature
was a leftover from avoiding new imports. Standard JLS / Checkstyle style
expects imports for non-conflicting JDK types.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the two parallel List<String> fields on LocalWitnesses
(pqPrivateKeys / pqPublicKeys) with a single List<PqKeypair> so the
index-alignment invariant is enforced by construction rather than by
runtime size-mismatch checks.

  - chainbase: new PqKeypair (Lombok @value) + LocalWitnesses uses it
  - framework: Args parses extended-hex entries directly into PqKeypair;
    WitnessInitializer / ConsensusService / RelayService consume pairs
  - test: rewritten to construct PqKeypair instances; the
    mismatched-list-size test is removed (impossible by construction)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…sactionSignWeight

Three changes in TransactionUtil.getTransactionSignWeight:
  - PQ signature validation now only runs when isAnyPqSchemeAllowed() is
    true, mirroring the rest of the PQ activation gating
  - Switches to the renamed validatePQSignatureGetWeight API, which owns
    its own signed-address dedup set internally (no more passing one in)
  - Always emits approveList / currentWeight on the builder, even when
    the transaction carries zero signatures of either kind

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lowed

Thread DynamicPropertiesStore through BlockCapsule#hasWitnessSignature so
a PQ-only block only reads as signed once at least one PQ scheme has been
governance-activated; before activation, only legacy ECDSA counts.

In BlockCapsule#validateSignature, simplify the PQ path:
  - drop the early "mutually exclusive" / "missing witness signature"
    checks; if PQ is allowed and pq_auth_sig is set, validate PQ — else
    fall through to legacy
  - tighten the PQ match: derive(pk) must equal
    AccountCapsule#getWitnessPermissionAddress() directly, no more
    iterating Permission.keys[]

Update VMActuator and Manager call sites to pass the store, plus the two
test classes that hit the renamed method.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 66b48fe1-d4c8-46df-88db-8fc1aac670b0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 14 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="chainbase/src/main/java/org/tron/common/utils/PqKeypair.java">

<violation number="1" location="chainbase/src/main/java/org/tron/common/utils/PqKeypair.java:12">
P1: `@Value` generates `toString()` including `privateKey`, which can leak secret key material in logs. Exclude this field from `toString()` generation.</violation>
</file>

<file name="chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java">

<violation number="1" location="chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java:211">
P1: Missing null-check on witness account can throw NullPointerException during signature validation.</violation>

<violation number="2" location="chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java:259">
P1: PQ signature address matching is restricted to a single witness key, which can reject valid signatures from other configured witness permission keys.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic

*/
@Value
public class PqKeypair {
String privateKey;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: @Value generates toString() including privateKey, which can leak secret key material in logs. Exclude this field from toString() generation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At chainbase/src/main/java/org/tron/common/utils/PqKeypair.java, line 12:

<comment>`@Value` generates `toString()` including `privateKey`, which can leak secret key material in logs. Exclude this field from `toString()` generation.</comment>

<file context>
@@ -0,0 +1,14 @@
+ */
+@Value
+public class PqKeypair {
+  String privateKey;
+  String publicKey;
+}
</file context>

matched = k;
break;
}
if (!Arrays.equals(derivedAddr, witnessPermissionAddress)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: PQ signature address matching is restricted to a single witness key, which can reject valid signatures from other configured witness permission keys.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java, line 259:

<comment>PQ signature address matching is restricted to a single witness key, which can reject valid signatures from other configured witness permission keys.</comment>

<file context>
@@ -262,38 +249,22 @@ private boolean validatePQSignature(DynamicPropertiesStore dynamicPropertiesStor
-        matched = k;
-        break;
-      }
+    if (!Arrays.equals(derivedAddr, witnessPermissionAddress)) {
+      throw new ValidateSignatureException(
+          "pq_auth_sig public key does not match witness permission address");
</file context>

if (dynamicPropertiesStore.getAllowMultiSign() != 1) {
witnessPermissionAddress = witnessAccountAddress;
} else {
witnessPermissionAddress = accountStore.get(witnessAccountAddress)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Missing null-check on witness account can throw NullPointerException during signature validation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At chainbase/src/main/java/org/tron/core/capsule/BlockCapsule.java, line 211:

<comment>Missing null-check on witness account can throw NullPointerException during signature validation.</comment>

<file context>
@@ -203,41 +201,27 @@ private Sha256Hash getRawHash() {
+    if (dynamicPropertiesStore.getAllowMultiSign() != 1) {
+      witnessPermissionAddress = witnessAccountAddress;
+    } else {
+      witnessPermissionAddress = accountStore.get(witnessAccountAddress)
+          .getWitnessPermissionAddress();
     }
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants