-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Enable key rotation in MPTokenIssuanceSet #7960
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
Open
yinyiqian1
wants to merge
1
commit into
XRPLF:ripple/confidential-key-rotation
Choose a base branch
from
yinyiqian1:allow-key-update
base: ripple/confidential-key-rotation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,7 +145,15 @@ MPTokenIssuanceSet::preflight(PreflightContext const& ctx) | |
| if (hasHolder && (hasIssuerElGamalKey || hasAuditorElGamalKey)) | ||
| return temMALFORMED; | ||
|
|
||
| if (hasAuditorElGamalKey && !hasIssuerElGamalKey) | ||
| // Pre-ConfidentialKeyRotation amendment, the auditor key could not be | ||
| // registered independently of the issuer key. The issuer could either: | ||
| // - Register only the issuer key (in which case an auditor key could not be added later), or | ||
| // - Register both the issuer and auditor keys simultaneously. | ||
| // | ||
| // Post-ConfidentialKeyRotation amendment, the auditor key can be | ||
| // registered after the issuer key has already been registered. | ||
| if (hasAuditorElGamalKey && !hasIssuerElGamalKey && | ||
| !ctx.rules.enabled(featureConfidentialKeyRotation)) | ||
| return temMALFORMED; | ||
|
|
||
| if (hasIssuerElGamalKey && !isValidCompressedECPoint(ctx.tx[sfIssuerEncryptionKey])) | ||
|
|
@@ -252,45 +260,61 @@ MPTokenIssuanceSet::preclaim(PreclaimContext const& ctx) | |
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| // Updating an existing encryption key requires the | ||
| // ConfidentialKeyRotation amendment. | ||
| bool const canRotateKey = ctx.view.rules().enabled(featureConfidentialKeyRotation); | ||
|
|
||
| bool const txHasIssuerKey = ctx.tx.isFieldPresent(sfIssuerEncryptionKey); | ||
| bool const txHasAuditorKey = ctx.tx.isFieldPresent(sfAuditorEncryptionKey); | ||
| bool const sleHasIssuerKey = sleMptIssuance->isFieldPresent(sfIssuerEncryptionKey); | ||
| bool const sleHasAuditorKey = sleMptIssuance->isFieldPresent(sfAuditorEncryptionKey); | ||
|
|
||
| // cannot update issuer public key | ||
| if (ctx.tx.isFieldPresent(sfIssuerEncryptionKey) && | ||
| sleMptIssuance->isFieldPresent(sfIssuerEncryptionKey)) | ||
| { | ||
| if (!canRotateKey && txHasIssuerKey && sleHasIssuerKey) | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| // cannot update auditor public key | ||
| if (ctx.tx.isFieldPresent(sfAuditorEncryptionKey) && | ||
| sleMptIssuance->isFieldPresent(sfAuditorEncryptionKey)) | ||
| { | ||
| if (!canRotateKey && txHasAuditorKey && sleHasAuditorKey) | ||
| return tecNO_PERMISSION; // LCOV_EXCL_LINE | ||
| } | ||
|
|
||
| // A first-time auditor key registration | ||
| // requires an issuer key, either already on the issuance or set by the | ||
| // same transaction. | ||
| bool const registersAuditorKey = txHasAuditorKey && !sleHasAuditorKey; | ||
| bool const issuerKeyExists = sleHasIssuerKey || txHasIssuerKey; | ||
| if (canRotateKey && registersAuditorKey && !issuerKeyExists) | ||
| return tecNO_PERMISSION; | ||
|
|
||
| if (enablesConfidentialAmount && sleMptIssuance->isFieldPresent(sfTransferFee) && | ||
| (*sleMptIssuance)[sfTransferFee] > 0u) | ||
| return tecNO_PERMISSION; | ||
|
|
||
| // Encryption keys can only be set if confidential amounts are already | ||
| // enabled on the issuance OR if the transaction is enabling it | ||
| if (ctx.tx.isFieldPresent(sfIssuerEncryptionKey) && | ||
| !sleMptIssuance->isFlag(lsfMPTCanHoldConfidentialBalance) && !enablesConfidentialAmount) | ||
| if (txHasIssuerKey && !sleMptIssuance->isFlag(lsfMPTCanHoldConfidentialBalance) && | ||
| !enablesConfidentialAmount) | ||
| { | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| if (ctx.tx.isFieldPresent(sfAuditorEncryptionKey) && | ||
| !sleMptIssuance->isFlag(lsfMPTCanHoldConfidentialBalance) && !enablesConfidentialAmount) | ||
| if (txHasAuditorKey && !sleMptIssuance->isFlag(lsfMPTCanHoldConfidentialBalance) && | ||
| !enablesConfidentialAmount) | ||
| { | ||
| return tecNO_PERMISSION; | ||
| } | ||
|
|
||
| // cannot upload key if there's circulating supply of COA | ||
| if ((ctx.tx.isFieldPresent(sfIssuerEncryptionKey) || | ||
| ctx.tx.isFieldPresent(sfAuditorEncryptionKey) || enablesConfidentialAmount) && | ||
| (*sleMptIssuance)[~sfConfidentialOutstandingAmount].value_or(0) > 0) | ||
| { | ||
| bool const hasConfidentialOA = | ||
| (*sleMptIssuance)[~sfConfidentialOutstandingAmount].value_or(0) > 0; | ||
|
|
||
| // Pre-ConfidentialKeyRotation amendment, keys cannot be uploaded while | ||
| // COA > 0. Post-amendment they can be uploaded even if COA > 0. | ||
| if (!canRotateKey && (txHasIssuerKey || txHasAuditorKey) && hasConfidentialOA) | ||
| return tecNO_PERMISSION; // LCOV_EXCL_LINE | ||
| } | ||
|
|
||
| // Enabling confidential balances when COA > 0 is not permitted, regardless of | ||
| // ConfidentialKeyRotation. | ||
| if (enablesConfidentialAmount && hasConfidentialOA) | ||
| return tecNO_PERMISSION; | ||
|
|
||
| return tesSUCCESS; | ||
| } | ||
|
|
@@ -397,7 +421,16 @@ MPTokenIssuanceSet::doApply() | |
| sle->getType() == ltMPTOKEN_ISSUANCE, | ||
| "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); | ||
|
|
||
| // Only increment the issuer key epoch on a rotation. A first-time registration leaves | ||
| // it absent (epoch 0), matching issuances whose keys were registered | ||
| // before the ConfidentialKeyRotation amendment. | ||
| // NOTE: presence must be checked before the key is overwritten below. | ||
| bool const isRotation = sle->isFieldPresent(sfIssuerEncryptionKey); | ||
|
|
||
| sle->setFieldVL(sfIssuerEncryptionKey, *pubKey); | ||
|
|
||
| if (isRotation) | ||
| (*sle)[sfIssuerKeyEpoch] = (*sle)[~sfIssuerKeyEpoch].valueOr(0) + 1; | ||
| } | ||
|
|
||
| if (auto const pubKey = ctx_.tx[~sfAuditorEncryptionKey]) | ||
|
|
@@ -407,7 +440,14 @@ MPTokenIssuanceSet::doApply() | |
| sle->getType() == ltMPTOKEN_ISSUANCE, | ||
| "MPTokenIssuanceSet::doApply : modifying MPTokenIssuance"); | ||
|
|
||
| // Only increment the auditor key epoch on a rotation. First time registration leaves it | ||
| // absent. | ||
| bool const isRotation = sle->isFieldPresent(sfAuditorEncryptionKey); | ||
|
Contributor
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. These 2 have the same code, why not make helper. or lambda? |
||
|
|
||
| sle->setFieldVL(sfAuditorEncryptionKey, *pubKey); | ||
|
|
||
| if (isRotation) | ||
| (*sle)[sfAuditorKeyEpoch] = (*sle)[~sfAuditorKeyEpoch].valueOr(0) + 1; | ||
| } | ||
|
|
||
| view().update(sle); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Best practices for amendments are using one amendment enabled block and one amendment disabled block, even if they are similar, instead of spreading amendment through the code.