Skip to content

Enable Threshold (1-of-N) Support in HTS Precompile - #1069

Closed
mgarbs wants to merge 9 commits into
mainfrom
update_token_keys
Closed

Enable Threshold (1-of-N) Support in HTS Precompile#1069
mgarbs wants to merge 9 commits into
mainfrom
update_token_keys

Conversation

@mgarbs

@mgarbs mgarbs commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Enable Threshold Keys Support in HTS updateTokenKeys Precompile

This update adds support for using threshold keyswithin the updateTokenKeys HTS precompile function, allowing developers to set token keys with multiple signatories directly in smart contracts. While complex keys are supported in the SDK, this enhancement allows on-chain token management with multi-signature and threshold-controlled permissions, expanding flexibility for applications requiring decentralized control over token keys.

@netlify

netlify Bot commented Oct 31, 2024

Copy link
Copy Markdown

Deploy Preview for hedera-hips ready!

Name Link
🔨 Latest commit 2e4a81d
🔍 Latest deploy log https://app.netlify.com/sites/hedera-hips/deploys/67a4cdf82412fa00082e300b
😎 Deploy Preview https://deploy-preview-1069--hedera-hips.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment thread HIP/hip-1069.md Outdated
@mgarbs
mgarbs requested a review from Nana-EC January 23, 2025 16:20
@mgarbs
mgarbs requested a review from ty-swirldslabs January 29, 2025 17:25
@Neurone

Neurone commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

Hi @mgarbs , it seems to me we solved all the pending issues. From my PoV we can proceed.

@lukelee-sl

lukelee-sl commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

From a technical point of view, I do not think this can be accommodated without system contract versioning as you would be potentially breaking existing contracts because of the need to redefine the KeyValue struct. If this is indeed the case, then we need to decide if this feature should be included in the next HTS contract version.

@stoyanov-st

Copy link
Copy Markdown
Contributor

I totally agree with @lukelee-sl, this is a great candidate for the contract versioning initiative.
Also, does it make sense to include the solidity struct changes with the HIP?

@Neurone

Neurone commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

I agree that this is a good fit for the new contract versioning initiative.

@lukelee-sl I don't think we need to make an explicit reference to this detail in the HIP, especially if the new process is going to be the new norm, but just in case, feel free to suggest some changes.

@stoyanov-st Yes, we need to make as many details explicit as possible, but they can be just an example and the real struct can be defined later. The guidelines for a HIP are to make explicit any changes that affect the operation of the network, including interfaces. In this case, if we maintain compatibility with old contracts, as we will now do with the versioning system, we can more easily skip all the details on the Solidity side, but it's good to have them as an initial idea and as a reference for developers reading the HIPs in the future. If there are major changes during development, we can always update the HIP with the correct interfaces, but if there are major changes, we will need to do a new HIP release.

@david-bakin-sl david-bakin-sl changed the title Enable KeyList Support in HTS Precompile Enable Threshold (1-of-N) Support in HTS Precompile Feb 7, 2025
@stoyanov-st

Copy link
Copy Markdown
Contributor

After carefully reviewing this HIP, the smart contracts team has agreed on several discussion topics that need to be addressed for the clarity and understanding of this feature. Those are:

  1. Solidity Structure Updates
  • A review of existing Solidity structures is necessary to ensure compatibility with the proposed changes.
  • Notably, due to recursion issues in KeyList we must determine whether to modify existing structures or introduce new ones to handle key management more efficiently.
  • If we follow the protobuf definitions for the structs modification there would be additional validation for the threshold = 1 that would require an appropriate response code for the unsuccessful scenarios.
  • Also, KeyHelper.sol needs adjustments.
  1. Other Threshold Limitations
  • While a threshold of 1 is the obvious limit, we need to address the more complex scenarios, such as a threshold within a threshold.
  • Defining these limitations early will help avoid ambiguity in implementation, misinterpretations and potential security concerns.
  1. Specification of Key Usage for Signing Transactions
  • A clear specification is needed regarding who signs transactions and which keys are used in different scenarios or a reference to an existing specification.
  1. System Contract Address
  • As this feature is going to be leveraging the System Contract Versioning, there needs to be a section stating the address that is going to be exposing it.

Considering the impact that this proposal is going to make, we need to be careful and also be able to foresee most of the implications that it is going to produce.

Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
@mgarbs
mgarbs requested a review from a team as a code owner September 25, 2025 18:36
Signed-off-by: Michael Garber <michael.garber@hashgraph.com>
@mgarbs
mgarbs requested a review from a team as a code owner September 25, 2025 18:55
@mgarbs
mgarbs removed the request for review from Ferparishuertas September 25, 2025 18:55
Comment thread _layouts/default.html
<script src="{{ '/assets/js/hipstable.js' | relative_url }}"></script>
<script src="{{ '/assets/js/filter.js' | relative_url }}"></script>
<script src="{{ '/assets/js/pr-integration.js' | relative_url }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>

Check warning

Code scanning / CodeQL

Inclusion of functionality from an untrusted source

Script loaded from content delivery network with no integrity check.
Comment thread scripts/validateHIP.js
draftHip = draftHip
.replace(/—/g, '-') // em dash to hyphen
.replace(/–/g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces ''' with itself.

Copilot Autofix

AI 12 months ago

To fix this problem, replace the no-op .replace(/'/g, "'") and .replace(/"/g, '"') calls with replacements that actually target unicode smart quotes, substituting them with regular ASCII single ' and double " quotes, respectively. Specifically:

  • Change the patterns to match the unicode smart quotes: (U+2018) and (U+2019) for single quotes, and (U+201C) and (U+201D) for double quotes.
  • Replace them with the ASCII equivalents (' and ").
  • Remove the unnecessary no-op replacements.

All changes should be made in the block of code that does the replacements (lines 45–56 in scripts/validateHIP.js). No new imports or dependencies are required.


Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -45,15 +45,12 @@
     draftHip = draftHip
       .replace(/—/g, '-')  // em dash to hyphen
       .replace(/–/g, '-')  // en dash to hyphen
-      .replace(/'/g, "'")  // left single quote
-      .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      // Replace smart single quotes to ASCII single quote
+      .replace(/[\u2018\u2019]/g, "'")
+      // Replace smart double quotes to ASCII double quote
+      .replace(/[\u201C\u201D]/g, '"')
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -45,15 +45,12 @@
draftHip = draftHip
.replace(//g, '-') // em dash to hyphen
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
// Replace smart single quotes to ASCII single quote
.replace(/[\u2018\u2019]/g, "'")
// Replace smart double quotes to ASCII double quote
.replace(/[\u201C\u201D]/g, '"')
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/—/g, '-') // em dash to hyphen
.replace(/–/g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces ''' with itself.

Copilot Autofix

AI 12 months ago

To fix this issue, update all redundant .replace(/'/g, "'") and .replace(/"/g, '"') calls to actually target the typographic/smart quote Unicode characters commonly found in documents, replacing them with plain ASCII equivalents. Specifically:

  • Replace left/right single quotes ( is U+2018, is U+2019) with '
  • Replace left/right double quotes ( is U+201C, is U+201D) with "
    This should be done in the replacement block for lines 44-56 in scripts/validateHIP.js.
    No new imports or dependencies are needed.

Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -45,15 +45,10 @@
     draftHip = draftHip
       .replace(/—/g, '-')  // em dash to hyphen
       .replace(/–/g, '-')  // en dash to hyphen
-      .replace(/'/g, "'")  // left single quote
-      .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      .replace(/[\u2018\u2019]/g, "'")  // left/right single quotes to ASCII
+      .replace(/[\u201C\u201D]/g, '"')  // left/right double quotes to ASCII
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -45,15 +45,10 @@
draftHip = draftHip
.replace(//g, '-') // em dash to hyphen
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
.replace(/[\u2018\u2019]/g, "'") // left/right single quotes to ASCII
.replace(/[\u201C\u201D]/g, '"') // left/right double quotes to ASCII
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/–/g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces '"' with itself.

Copilot Autofix

AI 12 months ago

The fix requires identifying the intended problematic characters (smart quotes), and replacing them with correct ASCII equivalents. Specifically:

  • Lines like .replace(/"/g, '"') should target the Unicode smart quotes, for example, replacing U+201C (\u201C) and U+201D (\u201D) with ".
  • Instead of .replace(/"/g, '"'), use .replace(/\u201C/g, '"') and .replace(/\u201D/g, '"').
  • Clean up redundant replacements of ' as well, if applicable (so-called "smart" single quotes U+2018/U+2019).
  • Only modify the draftHip clean-up chain in scripts/validateHIP.js (lines 45–56).
  • No new imports required.
  • No change to overall functionality, only correct the character replacement.

Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -45,15 +45,15 @@
     draftHip = draftHip
       .replace(/—/g, '-')  // em dash to hyphen
       .replace(/–/g, '-')  // en dash to hyphen
-      .replace(/'/g, "'")  // left single quote
-      .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      .replace(/\u2018/g, "'")  // left single quote
+      .replace(/\u2019/g, "'")  // right single quote
+      .replace(/\u201C/g, '"')  // left double quote
+      .replace(/\u201D/g, '"')  // right double quote
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
+      // .replace(/'/g, "'")  // another type of smart quote (u2019), handled above
+      // .replace(/"/g, '"')  // another type of smart quote (u201C), handled above
+      // .replace(/"/g, '"'); // another type of smart quote (u201D), handled above
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -45,15 +45,15 @@
draftHip = draftHip
.replace(//g, '-') // em dash to hyphen
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
.replace(/\u2018/g, "'") // left single quote
.replace(/\u2019/g, "'") // right single quote
.replace(/\u201C/g, '"') // left double quote
.replace(/\u201D/g, '"') // right double quote
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)
// .replace(/'/g, "'") // another type of smart quote (u2019), handled above
// .replace(/"/g, '"') // another type of smart quote (u201C), handled above
// .replace(/"/g, '"'); // another type of smart quote (u201D), handled above

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces '"' with itself.

Copilot Autofix

AI 12 months ago

To fix the problem, the code should replace specific Unicode quote characters (such as left/right smart quotes) with their ASCII equivalents (' and "), rather than replacing the ASCII quote with itself. The affected region is lines 48–56 in scripts/validateHIP.js. Specifically, the code should use the corresponding Unicode code points for smart quotes — e.g., replace / with ', and / with " — not generic ASCII quotes.

To implement these changes, update the relevant .replace() calls to properly match and convert Unicode smart quotes to ASCII quotes. No additional imports or custom methods are required; all replacements can be done using JS regular expressions.

Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -45,15 +45,15 @@
     draftHip = draftHip
       .replace(/—/g, '-')  // em dash to hyphen
       .replace(/–/g, '-')  // en dash to hyphen
-      .replace(/'/g, "'")  // left single quote
-      .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      .replace(/[\u2018]/g, "'")   // left single quotation mark (‘) to ASCII single quote
+      .replace(/[\u2019]/g, "'")   // right single quotation mark (’) to ASCII single quote
+      .replace(/[\u201C]/g, '"')   // left double quotation mark (“) to ASCII double quote
+      .replace(/[\u201D]/g, '"')   // right double quotation mark (”) to ASCII double quote
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
+      // removed duplicate smart quote replaces since they're now handled above
+      // removed duplicate smart quote replaces since they're now handled above
+      // removed duplicate smart quote replaces since they're now handled above
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -45,15 +45,15 @@
draftHip = draftHip
.replace(//g, '-') // em dash to hyphen
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
.replace(/[\u2018]/g, "'") // left single quotation mark (‘) to ASCII single quote
.replace(/[\u2019]/g, "'") // right single quotation mark (’) to ASCII single quote
.replace(/[\u201C]/g, '"') // left double quotation mark (“) to ASCII double quote
.replace(/[\u201D]/g, '"') // right double quotation mark (”) to ASCII double quote
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)
// removed duplicate smart quote replaces since they're now handled above
// removed duplicate smart quote replaces since they're now handled above
// removed duplicate smart quote replaces since they're now handled above

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/"/g, '"') // right double quote
.replace(/…/g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces ''' with itself.

Copilot Autofix

AI 12 months ago

To fix the problem, locate the .replace(/'/g, "'") on line 54, which is intended to convert smart single quotes (such as U+2019) to ASCII apostrophes. Change the regular expression so it matches the correct Unicode code point(s) for smart quotes—for example, \u2019 (right single quotation mark), \u2018 (left single quotation mark), and possibly others—then replace them with the simple ASCII apostrophe ('). No additional imports are needed as this uses JavaScript's built-in string and regex support. Only change the code on or near line 54 for this correction.


Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -51,7 +51,7 @@
       .replace(/"/g, '"')  // right double quote
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
+      .replace(/[\u2018\u2019]/g, "'")  // left/right single quotation marks to apostrophe
       .replace(/"/g, '"')  // another type of smart quote (u201C)
       .replace(/"/g, '"'); // another type of smart quote (u201D)
 
EOF
@@ -51,7 +51,7 @@
.replace(/"/g, '"') // right double quote
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/[\u2018\u2019]/g, "'") // left/right single quotation marks to apostrophe
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)

Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/…/g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces '"' with itself.

Copilot Autofix

AI 12 months ago

To properly standardize double quotes in the HIP text, we should replace all forms of "smart quotes" with the standard ASCII double quote character ("). This means explicitly targeting Unicode characters such as (LEFT DOUBLE QUOTATION MARK, U+201C) and (RIGHT DOUBLE QUOTATION MARK, U+201D). Lines 50, 51, 55, and 56 currently use /"/g, which matches only the ASCII double quote, but they should use /[“”]/g to replace these Unicode types. Thus, in file scripts/validateHIP.js, lines 50, 51, 55, and 56 should match these Unicode smart quotes and replace with ".

No external dependency is needed; only native JavaScript regex.


Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -47,13 +47,13 @@
       .replace(/–/g, '-')  // en dash to hyphen
       .replace(/'/g, "'")  // left single quote
       .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      .replace(/“/g, '"')  // left double quote U+201C
+      .replace(/”/g, '"')  // right double quote U+201D
       .replace(/…/g, '...') // ellipsis
       .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
       .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
+      .replace(/“/g, '"')  // another type of smart quote (redundant, left quote)
+      .replace(/”/g, '"'); // another type of smart quote (redundant, right quote)
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -47,13 +47,13 @@
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
.replace(//g, '"') // left double quote U+201C
.replace(//g, '"') // right double quote U+201D
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)
.replace(//g, '"') // another type of smart quote (redundant, left quote)
.replace(//g, '"'); // another type of smart quote (redundant, right quote)

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
Comment thread scripts/validateHIP.js
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)

Check warning

Code scanning / CodeQL

Replacement of a substring with itself

This replaces '"' with itself.

Copilot Autofix

AI 12 months ago

General fix:
Remove or correct the .replace lines where the code attempts to replace a substring with itself (/"/g, '"') for both single and double quotes. Instead, the code should explicitly match and replace smart/curly quotes (such as , , , ) with the ASCII equivalents. This will ensure that all variants of smart quotes are handled correctly for JSON and downstream processing.

Specifics:

  • On lines 48–56, correct the regexes so that all Unicode smart quotes are matched, and are replaced with ASCII ' or " as appropriate.
  • Remove all lines that simply .replace(/'/g, "'") or .replace(/"/g, '"') unless they're meant to revert something that was previously mapped incorrectly (which seems not to be the intent here).
  • Add correct regex replacements for smart quote characters:
    • Single quotes: (U+2018), (U+2019)
    • Double quotes: (U+201C), (U+201D)

Implementation details:
Edit line 45–56 in scripts/validateHIP.js to:

  • Replace .replace(/‘|’/g, "'") // smart single quotes
  • Replace .replace(/“|”/g, '"') // smart double quotes
  • Remove any duplicate or no-op replacements.

No new imports are necessary.


Suggested changeset 1
scripts/validateHIP.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/scripts/validateHIP.js b/scripts/validateHIP.js
--- a/scripts/validateHIP.js
+++ b/scripts/validateHIP.js
@@ -45,15 +45,10 @@
     draftHip = draftHip
       .replace(/—/g, '-')  // em dash to hyphen
       .replace(/–/g, '-')  // en dash to hyphen
-      .replace(/'/g, "'")  // left single quote
-      .replace(/'/g, "'")  // right single quote
-      .replace(/"/g, '"')  // left double quote
-      .replace(/"/g, '"')  // right double quote
+      .replace(/[‘’]/g, "'")  // smart single quotes U+2018, U+2019 to ASCII
+      .replace(/[“”]/g, '"')  // smart double quotes U+201C, U+201D to ASCII
       .replace(/…/g, '...') // ellipsis
-      .replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
-      .replace(/'/g, "'")  // another type of smart quote (u2019)
-      .replace(/"/g, '"')  // another type of smart quote (u201C)
-      .replace(/"/g, '"'); // another type of smart quote (u201D)
+      .replace(/[\u2028\u2029]/g, '\n'); // line/paragraph separators
 
     // Check if API key is available
     if (!API_KEY) {
EOF
@@ -45,15 +45,10 @@
draftHip = draftHip
.replace(//g, '-') // em dash to hyphen
.replace(//g, '-') // en dash to hyphen
.replace(/'/g, "'") // left single quote
.replace(/'/g, "'") // right single quote
.replace(/"/g, '"') // left double quote
.replace(/"/g, '"') // right double quote
.replace(/[]/g, "'") // smart single quotes U+2018, U+2019 to ASCII
.replace(/[]/g, '"') // smart double quotes U+201C, U+201D to ASCII
.replace(//g, '...') // ellipsis
.replace(/[\u2028\u2029]/g, '\n') // line/paragraph separators
.replace(/'/g, "'") // another type of smart quote (u2019)
.replace(/"/g, '"') // another type of smart quote (u201C)
.replace(/"/g, '"'); // another type of smart quote (u201D)
.replace(/[\u2028\u2029]/g, '\n'); // line/paragraph separators

// Check if API key is available
if (!API_KEY) {
Copilot is powered by AI and may make mistakes. Always verify output.
@mgarbs mgarbs closed this Oct 22, 2025
@github-project-automation github-project-automation Bot moved this from In Review to Done in Smart Contract Sprint Board Oct 22, 2025
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.

6 participants