Skip to content
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

add example of decoding event on-chain #286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented Dec 13, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new state variables and methods in the Venus contract for enhanced functionality.
    • Added events for improved communication regarding transmissions between chains.
    • Implemented error handling for specific event validation scenarios.
  • Bug Fixes

    • Enhanced error handling mechanisms for event processing.
  • Chores

    • Updated version number in the project configuration.

Copy link

coderabbitai bot commented Dec 13, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: @typescript-eslint/[email protected]
npm error Found: @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/parser
npm error dev @typescript-eslint/parser@"^7.11.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @typescript-eslint/parser@"^8.0.0 || ^8.0.0-alpha.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/eslint-plugin
npm error dev @typescript-eslint/eslint-plugin@"^8.18.0" from the root project
npm error
npm error Conflicting peer dependency: @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/parser
npm error peer @typescript-eslint/parser@"^8.0.0 || ^8.0.0-alpha.0" from @typescript-eslint/[email protected]
npm error node_modules/@typescript-eslint/eslint-plugin
npm error dev @typescript-eslint/eslint-plugin@"^8.18.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /root/.npm/_logs/2024-12-13T22_12_34_049Z-eresolve-report.txt
npm error A complete log of this run can be found in: /root/.npm/_logs/2024-12-13T22_12_34_049Z-debug-0.log

Walkthrough

The pull request introduces significant updates to the Venus contract and its associated bindings. Key changes include the addition of new methods and events in the Venus.go file, enhancing the ABI with a new constructor parameter and functions for retrieving information about the counterparty and last received transmission. The Solidity contract Venus.sol is updated with new state variables, events, and error handling, while the TypeScript interfaces and factory classes are modified to accommodate these new functionalities. Additionally, the package.json file reflects a version increment.

Changes

File Path Change Summary
bindings/go/venus/Venus.go - Added methods: CounterParty, LastReceivedTransmission, and ReceiveTransmissionEvent
- Added types and iterators for new events
- Expanded ABI string with new events and methods.
contracts/examples/Venus.sol - Added state variables: counterParty, lastReceivedTransmission
- Added events: TransmitToHouston, TransmissionReceived
- Updated constructor and added new error handling.
package.json - Updated version from 4.0.15 to 4.0.16.
src/evm/contracts/Venus.ts - Updated getFunction and getEvent methods to include new functions and events
- Added encoding/decoding methods for new functions.
src/evm/contracts/factories/Venus__factory.ts - Updated constructor to include _counterParty
- Added methods for new functionalities and events related to transmissions.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • dshiell

🐰 In the world of code, where changes abound,
New methods and events, in Venus are found.
With counterparty links and transmissions in tow,
The contract grows stronger, as we all know!
So hop along, friends, let’s celebrate bright,
For Venus is shining, a marvelous sight! 🌟


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. (Experiment)
  • @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.

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: 3

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 23fb160 and 88ca080.

📒 Files selected for processing (5)
  • bindings/go/venus/Venus.go (4 hunks)
  • contracts/examples/Venus.sol (2 hunks)
  • package.json (1 hunks)
  • src/evm/contracts/Venus.ts (9 hunks)
  • src/evm/contracts/factories/Venus__factory.ts (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
🪛 Biome (1.9.4)
src/evm/contracts/Venus.ts

[error] 220-220: void is confusing outside a return type or a type parameter.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)


[error] 270-270: void is confusing outside a return type or a type parameter.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (4)
src/evm/contracts/factories/Venus__factory.ts (2)

28-32: Ensure constructor parameters are correctly typed and documented

The constructor now includes the '_counterParty' parameter. Verify that all usages of the constructor pass the correct address and that the parameter is properly documented.


284-297: Update deployment functions to include '_counterParty'

The 'getDeployTransaction' and 'deploy' methods have been updated to include '_counterParty'. Ensure that any scripts or tools that deploy this contract are updated to provide this new parameter.

bindings/go/venus/Venus.go (1)

34-34: Go bindings updated to reflect new contract interface

The Go bindings have been correctly updated to include new methods and events corresponding to the contract changes.

Also applies to: 183-244, 318-338, 609-742, 744-877

src/evm/contracts/Venus.ts (1)

185-188: Methods appropriately added for new contract functions

The methods 'counterParty' and 'lastReceivedTransmission' have been correctly added with proper types.

Comment on lines +154 to +160
if (address(uint160(uint256(bytes32(emittingAddress)))) != counterParty) {
// If this triggers, we have received a valid event from the source chain with a valid proof,
// but it was emitted from a wrong address. This would likely be someone trying to spoof another contract's
// event.
// This validation is important since any contract can emit any event.
revert invalidEventSender();
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential incorrect address conversion in 'emittingAddress' comparison

The conversion of 'emittingAddress' to an address may not handle all cases correctly. Casting bytes to address should ensure proper length and formatting to avoid incorrect comparisons.

Update the address conversion to safely decode 'emittingAddress':

- if (address(uint160(uint256(bytes32(emittingAddress)))) != counterParty) {
+ if (abi.decode(emittingAddress, (address)) != counterParty) {
    // ...
}
📝 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
if (address(uint160(uint256(bytes32(emittingAddress)))) != counterParty) {
// If this triggers, we have received a valid event from the source chain with a valid proof,
// but it was emitted from a wrong address. This would likely be someone trying to spoof another contract's
// event.
// This validation is important since any contract can emit any event.
revert invalidEventSender();
}
if (abi.decode(emittingAddress, (address)) != counterParty) {
// If this triggers, we have received a valid event from the source chain with a valid proof,
// but it was emitted from a wrong address. This would likely be someone trying to spoof another contract's
// event.
// This validation is important since any contract can emit any event.
revert invalidEventSender();
}

Comment on lines +50 to +55
constructor(ICrossL2Prover _prover, address _counterParty) {
if (address(_prover) == address(0)) {
revert invalidProverAddress();
}
prover = _prover;
counterParty = _counterParty;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing validation for '_counterParty' address in constructor

The '_counterParty' parameter is not checked for the zero address. Assigning a zero address to 'counterParty' could lead to unexpected behavior or security risks.

Consider adding a validation check for '_counterParty':

constructor(ICrossL2Prover _prover, address _counterParty) {
    if (address(_prover) == address(0)) {
        revert invalidProverAddress();
    }
    prover = _prover;
+   if (_counterParty == address(0)) {
+       revert invalidCounterPartyAddress();
+   }
    counterParty = _counterParty;
}

Also, define the new error:

+ error invalidCounterPartyAddress();

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +220 to +221
[void],
"nonpayable"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace 'void' with 'undefined' in method output types

Using 'void' outside of return type positions can be confusing in TypeScript. It's recommended to use 'undefined' for output tuple types.

Apply this change:

      receiveTransmissionEvent: TypedContractMethod<
        [
          receiptIndex: BytesLike,
          receiptRLPEncodedBytes: BytesLike,
          logIndex: BigNumberish,
          proof: BytesLike
        ],
-       [void],
+       [undefined],
        "nonpayable"
      >;

Similarly, update other instances where '[void]' is used as an output type.

Also applies to: 270-271

🧰 Tools
🪛 Biome (1.9.4)

[error] 220-220: void is confusing outside a return type or a type parameter.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

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.

1 participant