Skip to content

Conversation

SimonVutovB
Copy link
Contributor

Summary

Added token enablement validation and tests

Changes

  • Inside, verifyTransaction in near.ts of sdk-coin-near, validate the txHex is a valid token enablement transaction for the specified token and does not have additional transactions embedded.

TICKET: WP-5782

@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch 3 times, most recently from 3371efc to b81a0d0 Compare September 11, 2025 19:21
Copy link
Contributor

@mtexeira-simtlix mtexeira-simtlix left a comment

Choose a reason for hiding this comment

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

A few changes requested but you got a general first idea, good job! let me know if you need further clarification on any of the mentioned points @SimonVutovB

Thanks!

@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from 8d0fb13 to fa835c7 Compare September 15, 2025 17:41
@mtexeira-simtlix
Copy link
Contributor

@SimonVutovB for this issue that you're getting on the CI/CD steps, just rebase master since your dep versions are out of date:

image

@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from fa835c7 to cf059f2 Compare September 16, 2025 13:16
@SimonVutovB SimonVutovB requested review from a team as code owners September 16, 2025 13:16
@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from cf059f2 to 6141074 Compare September 16, 2025 13:31
@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from e9cbf28 to 10c27f8 Compare September 16, 2025 17:36
Copy link
Contributor

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo left a comment

Choose a reason for hiding this comment

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

add a unit test to show sendTokenEnablements throws an error when you mock a response with a spoofed TxHex. Otherwise lgtm.

Copy link
Contributor

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo left a comment

Choose a reason for hiding this comment

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

please add a test case showcasing sendAccountConsolidations fails when a spoofed txHex is returned in the response.

@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from f4a41a4 to 3be12f4 Compare September 24, 2025 18:00
Copy link
Contributor

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo left a comment

Choose a reason for hiding this comment

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

Can we add a test that shows a spoofed tx from platform will be rejected, similar to HBAR's?

Copy link
Contributor

@balakrishna507 balakrishna507 left a comment

Choose a reason for hiding this comment

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

i'll also request a review from the coin owners.

const explainedTx = transaction.explainTransaction();

// users do not input recipients for consolidation requests as they are generated by the server
if (txParams.type === 'enabletoken') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (txParams.type === 'enabletoken') {
if (txParams.type === 'enabletoken' && verification.verifyTokenEnablement) {

Copy link
Contributor

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo left a comment

Choose a reason for hiding this comment

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

LGTM, missing one last change.

FloBitGo
FloBitGo previously approved these changes Oct 3, 2025

if (!_.isEqual(filteredOutputs, filteredRecipients)) {
// For enabletoken, provide more specific error messages for address mismatches
if (txParams.type === 'enabletoken') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (txParams.type === 'enabletoken') {
if (txParams.type === 'enabletoken' && params.verification?.verifyTokenEnablement) {

Not sure if we always want to throw this new error or only if the param is passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you're right, good catch. Just pushed change to add the check for the verifyTokenEnablement flag.

mukeshsp
mukeshsp previously approved these changes Oct 7, 2025
Copy link
Contributor

@mukeshsp mukeshsp left a comment

Choose a reason for hiding this comment

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

Please squash all the commits into a single commit.

NEAR token enablement blind signing validation

TICKET: WP-5782
@SimonVutovB SimonVutovB force-pushed the WP-5782/fix-near-token-enablement-validation branch from 8f353e7 to d84bba2 Compare October 7, 2025 13:04
@sijuu
Copy link
Contributor

sijuu commented Oct 10, 2025

PR has merge conflicts

lerna.json Outdated
{
"version": "independent",
"npmClient": "yarn",
"packages": ["modules/*"],
Copy link
Contributor

Choose a reason for hiding this comment

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

is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I deleted it and all checks pass, so I guess it was not needed.

// The result should contain failures due to the spoofed transaction hex
result.success.should.have.length(0);
result.failure.should.have.length(1);
result.failure[0].message.should.containEql('unable to build transaction from raw');
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how this is testing that the spoofed transaction does not match the intended transaction?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree with @mohammadalfaiyazbitgo , I don't remember how the internal flow goes exactly but if you mock the build results then you're basically shutting down the internal verifies somewhere.

@SimonVutovB mind trying an approach similar to what I did in this other tests? It's also a little shorter and you may throw an error msg that should be the same as one of your token enablement error msg's on the current PR:
image

For ref, this is on modules/sdk-coin-xlm/test/unit/xlm.ts , look for the test name on that file please.

const output = explainedTx.outputs[0];
const recipient = txParams.recipients?.[0];

if (!recipient?.address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you confirm if near token enablements supports a single recipient? because if that's the case then you may need to check for outputs.length === 1 and if it isn't then you may need to iterate over the outputs or recipients and match one with the other (also you can preliminary compare outputs.length with recipients.length and they should match).

// The result should contain failures due to the spoofed transaction hex
result.success.should.have.length(0);
result.failure.should.have.length(1);
result.failure[0].message.should.containEql('unable to build transaction from raw');
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I agree with @mohammadalfaiyazbitgo , I don't remember how the internal flow goes exactly but if you mock the build results then you're basically shutting down the internal verifies somewhere.

@SimonVutovB mind trying an approach similar to what I did in this other tests? It's also a little shorter and you may throw an error msg that should be the same as one of your token enablement error msg's on the current PR:
image

For ref, this is on modules/sdk-coin-xlm/test/unit/xlm.ts , look for the test name on that file please.

Unit tests for tokenEnablementValidation changes

and Making sure there is 1 user in the txParams.recipients

TICKET: WP-5782
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.

8 participants