Skip to content

Conversation

@dev2-nomo
Copy link
Collaborator

@dev2-nomo dev2-nomo commented Feb 5, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a configurable option for stricter RLP decoding, offering improved flexibility in handling RLP data.
  • Tests

    • Enhanced the test suite by reinstating scenarios for invalid RLP encodings to ensure robust detection and handling of improper inputs.
    • Added a new test case to validate error handling when parsing hex strings with strict RLP decoding enabled.

@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

This change introduces a new global boolean variable STRICT_RLP_DECODE in the RLP utilities to allow conditional enforcement of strict decoding rules, rather than a hardcoded behavior. The decodeRLP function now checks this variable to decide if it should throw an exception for single-byte results less than 0x80. Additionally, tests for invalid RLP encodings have been enabled by uncommenting a previously inactive test group to ensure that invalid inputs correctly trigger exceptions.

Changes

File(s) Change Summary
lib/.../rlp.dart Added a global boolean STRICT_RLP_DECODE (default true) that controls strict RLP decoding in decodeRLP, allowing flexible exception handling based on its value.
test/.../rlp_test.dart Uncommented and integrated tests for invalid RLP encodings to verify that decodeRLPCheck throws an RLPException when encountering invalid hexadecimal inputs.
test/.../parse_hex_transaction_test.dart Added a test case to check that RawEvmTransaction creation throws an RLPException when STRICT_RLP_DECODE is true with invalid input, and verifies successful creation with it set to false.

Possibly related PRs

Suggested reviewers

  • nomo-app
  • ThomasFercher

Poem

Hopping through lines of code, I smile with delight,
A new strict flag shines, ensuring correctness in sight.
Decoding RLP with care and grace,
Testing the edges in every place.
From burrows deep, I cheer each fix—
A rabbit’s joy in each new mix! 🐰
Code leaps high into the night!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dev2-nomo
Copy link
Collaborator Author

Reverted back to old tests and introduced the STRICT_RLP_DECODE Flag which is enabled by default.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/src/crypto/evm/utils/rlp.dart (1)

6-8: Consider making the variable immutable and scoped.

The global mutable state can lead to unpredictable behavior if modified during runtime. Consider:

  1. Making it final to prevent modification after initialization
  2. Moving it into a configuration class to better manage the state

Also, there's a typo in the documentation: "recommned" should be "recommend".

-/// We recommned leaving this enabled unless you have a specific reason to disable it.
+/// We recommend leaving this enabled unless you have a specific reason to disable it.
-bool STRICT_RLP_DECODE = true;
+final bool STRICT_RLP_DECODE = true;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30d0afd and 9d18b0f.

📒 Files selected for processing (2)
  • lib/src/crypto/evm/utils/rlp.dart (2 hunks)
  • test/ci/rlp/rlp_test.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test/ci/tron tests
  • GitHub Check: test/ci/proof_of_payment tests
  • GitHub Check: test/ci/fetching tests
  • GitHub Check: test/ci/evm tests
  • GitHub Check: test/ci/derivation tests
🔇 Additional comments (2)
lib/src/crypto/evm/utils/rlp.dart (1)

285-285: LGTM! Conditional check for strict RLP decoding.

The implementation correctly uses the STRICT_RLP_DECODE flag to conditionally enforce strict RLP decoding rules.

test/ci/rlp/rlp_test.dart (1)

356-372: LGTM! Comprehensive test coverage for invalid RLP encodings.

The test cases effectively verify that invalid RLP encodings are properly rejected. The commented explanation for the excluded test case is helpful.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/ci/evm/parsing/parse_hex_transaction_test.dart (1)

55-56: Improve test isolation by using setUp and tearDown.

Modifying a global flag directly in the test could affect other tests if they run in parallel. Consider using setUp and tearDown to manage the flag state.

Apply this diff to improve test isolation:

 test('Parse hex string to RawEvmTransaction', () {
-  STRICT_RLP_DECODE = true;
+  setUp(() {
+    STRICT_RLP_DECODE = true;
+  });
+
+  tearDown(() {
+    STRICT_RLP_DECODE = false;
+  });
+
   const msgHex =
       "f86b8151843b9aca00830124f894e9e7CEA3DedcA5984780Bafc599bD69ADd087D5680b844a9059cbb000000000000000000000000a7fa4bb0bba164f999e8c7b83c9da96a3be44616000000000000000000000000000000000000000000000000000000000000271081388080";

   expect(
     () => RawEvmTransaction.fromUnsignedHex(msgHex),
     throwsA(
       isA<RLPException>(),
     ),
   );

-  STRICT_RLP_DECODE = false;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9d18b0f and b7db9d9.

📒 Files selected for processing (1)
  • test/ci/evm/parsing/parse_hex_transaction_test.dart (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test/ci/tron tests
  • GitHub Check: test/ci/proof_of_payment tests
  • GitHub Check: test/ci/fetching tests
  • GitHub Check: test/ci/evm tests
  • GitHub Check: test/ci/derivation tests

Comment on lines +44 to +54
STRICT_RLP_DECODE = true;
const msgHex =
"f86b8151843b9aca00830124f894e9e7CEA3DedcA5984780Bafc599bD69ADd087D5680b844a9059cbb000000000000000000000000a7fa4bb0bba164f999e8c7b83c9da96a3be44616000000000000000000000000000000000000000000000000000000000000271081388080";

expect(
() => RawEvmTransaction.fromUnsignedHex(msgHex),
throwsA(
isA<RLPException>(),
),
);

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing import or declaration for STRICT_RLP_DECODE.

The test uses STRICT_RLP_DECODE without importing or declaring it. This could cause compilation errors.

Add the import statement at the beginning of the file:

import 'package:walletkit_dart/walletkit_dart.dart';
+import 'package:walletkit_dart/src/crypto/evm/utils/rlp.dart' show STRICT_RLP_DECODE;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
STRICT_RLP_DECODE = true;
const msgHex =
"f86b8151843b9aca00830124f894e9e7CEA3DedcA5984780Bafc599bD69ADd087D5680b844a9059cbb000000000000000000000000a7fa4bb0bba164f999e8c7b83c9da96a3be44616000000000000000000000000000000000000000000000000000000000000271081388080";
expect(
() => RawEvmTransaction.fromUnsignedHex(msgHex),
throwsA(
isA<RLPException>(),
),
);
// At the top of test/ci/evm/parsing/parse_hex_transaction_test.dart
import 'package:walletkit_dart/walletkit_dart.dart';
import 'package:walletkit_dart/src/crypto/evm/utils/rlp.dart' show STRICT_RLP_DECODE;
// ... other imports or file header contents
void main() {
// ... possibly other tests and setup
test('Parsing hex transaction with strict RLP decode enabled', () {
STRICT_RLP_DECODE = true;
const msgHex =
"f86b8151843b9aca00830124f894e9e7CEA3DedcA5984780Bafc599bD69ADd087D5680b844a9059cbb000000000000000000000000a7fa4bb0bba164f999e8c7b83c9da96a3be44616000000000000000000000000000000000000000000000000000000000000271081388080";
expect(
() => RawEvmTransaction.fromUnsignedHex(msgHex),
throwsA(
isA<RLPException>(),
),
);
});
}

@dev2-nomo dev2-nomo merged commit 35a5ffd into main Feb 5, 2025
13 checks passed
@dev2-nomo dev2-nomo deleted the rlp_fix_again branch February 5, 2025 15:56
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.

3 participants