Skip to content

feat(stylus) - governance (minus upgrade contract) #2877

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

Merged
merged 54 commits into from
Jul 23, 2025

Conversation

ayushboss
Copy link
Contributor

@ayushboss ayushboss commented Jul 21, 2025

Summary

This PR implements governance instruction handling for the Pyth Receiver on the stylus framework. It incorporates most instructions, except for UpgradeContract.

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Added new tests for the instructions. Can't manually verify changed parameters, so existing tests make sure that the exact same instruction cant be submitted twice to check whether the first instruction was processed. Some methods can't be tested without fully deployed contracts, due to the limitations of motsu.

ayushboss and others added 30 commits July 11, 2025 15:33
- Translate governance logic from StarkNet to Stylus/Rust patterns
- Implement parse_instruction function with proper byte parsing
- Add governance-specific error types to PythReceiverError enum
- Replace StarkNet types (ContractAddress, ByteBuffer) with Stylus equivalents
- Use Rust idiomatic patterns for data structures and error handling
- Support all governance actions: UpgradeContract, SetDataSources, SetFee, etc.
- Add proper imports and module structure for governance functionality

Fixes compilation errors and provides complete governance parsing capability
for the Stylus implementation following Rust best practices.

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Remove duplicate Cairo-style GovernancePayload enum definition
- Fix match statement to use proper GovernancePayload:: enum prefixes
- Fix VAA field access from vm.payload to vm.body.payload
- Fix upgrade_contract parameter type to match UpgradeContract struct
- Move verify_governance_vm outside impl block to resolve AbiType issues
- Fix chain_id type conversion and mutability issues

All compilation errors resolved and tests passing. Match statement structure
now properly replicates the Cairo implementation skeleton.

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Fix SetDataSources function signature and implementation
- Fix SetWormholeAddress function signature and parameter handling
- Fix AuthorizeGovernanceTransfer function with proper config handling
- Implement SetValidPeriod parsing and handler function
- Resolve type mismatches and move semantics issues
- All cargo tests now pass successfully

The governance functions now align with the Solidity PythGovernance.sol implementation and handle governance messages correctly.

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Iterate through existing valid_data_sources to invalidate them in is_valid_data_source mapping
- Clear the storage vector using truncate(0) before adding new data sources
- Match Solidity PythGovernance.sol behavior: invalidate old sources, clear array, add new sources
- Fix unused Result warning in authorize_governance_transfer call
- All cargo tests pass (13 passed, 0 failed)

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Add Erase trait implementation for DataSourceStorage struct
- Update set_data_sources function to use erase() instead of truncate(0)
- Provides better storage cleanup by properly erasing each field
- Matches Solidity behavior: invalidate old sources, clear storage, add new sources
- All cargo tests pass (13 passed, 0 failed)

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Add SetTransactionFee (8) and WithdrawFee (9) to GovernanceAction enum
- Implement parsing logic for both actions matching Solidity implementation
- Add TODO comments for event emissions to match EVM contract behavior
- Ensure instruction parsing compatibility between Stylus and Solidity

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Add FeeSet, TransactionFeeSet, FeeWithdrawn, ValidPeriodSet events using sol! macro
- Implement event emissions in set_fee, set_valid_period, set_transaction_fee, withdraw_fee functions
- Replace TODO comments with actual evm::log calls following Arbitrum Stylus patterns
- Maintain cross-chain consistency with Fuel/Starknet event structures (old_fee/new_fee)
- All 13 tests pass, no regressions in existing governance functionality

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Add GovernanceDataSourceSet event for authorize_governance_transfer()
- Add DataSourcesSet event for set_data_sources()
- All governance instructions now emit corresponding events
- Maintains cross-chain consistency with Fuel/Starknet implementations

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Updated all 6 instances of evm::log to use log(vm, event) syntax
- Removed unused evm import from stylus_sdk imports
- All tests pass successfully (13 passed; 0 failed)
- Eliminates deprecation warnings for logging functions

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
…ion data sources

- Parse governance instruction from hex VAA to extract SetDataSources payload
- Verify that extracted data sources match expected values (chain_id=1, emitter ending in 0x1111)
- Update guardian setup to use simple sequential addresses instead of current_guardians()
- Clean up unused imports and constants
- All tests now pass successfully with cargo test

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
…to show meaningful error messages in tests

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
…AuthorizeGovernanceDataSourceTransfer, SetTransactionFee, and WithdrawFee

- Added 5 new test functions following existing test structure
- Tests focus on Wormhole verification and instruction parsing
- Uses guardian address 0x7e5f4552091a69125d5dfcb7b8c2659029395bdf
- Note: Tests currently fail due to signature verification issues that need to be addressed

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
- Updated 5 governance test VAAs with correct signatures using guardian key 1
- Added GenerateGovernanceVAAs.t.sol Foundry script for VAA generation
- 3/5 tests now pass: test_set_fee_in_token, test_set_transaction_fee, test_set_wormhole_address
- 2 tests still failing due to payload/state issues, not signature problems

Generated using Foundry's encodeAndSignMessage function with proper guardian setup.

Co-Authored-By: ayush.suresh@dourolabs.xyz <byteSlayer31037@gmail.com>
Copy link
Contributor

@tejasbadadare tejasbadadare left a comment

Choose a reason for hiding this comment

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

nice work! left some nits, feel free to address and merge. also feel free to address the comments about the tests in another PR.

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