Skip to content

Feat/staking evm event propagation - #2229

Merged
ogarciarevett merged 27 commits into
mainfrom
feat/staking-evm-event-propagation
Aug 12, 2025
Merged

ogarciarevett merged 27 commits into
mainfrom
feat/staking-evm-event-propagation

Conversation

@ogarciarevett

@ogarciarevett ogarciarevett commented Jul 9, 2025 •

Copy link
Copy Markdown
Contributor

Describe your changes and provide context

🎯 Summary

This PR adds EVM event emission to the Sei staking precompile, enabling standard Ethereum tooling compatibility while maintaining 100% backward compatibility.

📋 Context

Currently, Sei precompiles only emit events through the Cosmos SDK event system, making them invisible to EVM tools and indexers. This creates a fragmented experience for developers and limits integration with Ethereum ecosystem tools.

🔧 Changes

1. EVM Event Emission Infrastructure

  • Added helper functions in precompiles/common/evm_events.go:
    • EmitEVMLog: Generic function for emitting EVM logs
    • Specific emitters: EmitDelegateEvent, EmitRedelegateEvent, EmitUndelegateEvent, EmitValidatorCreatedEvent, EmitValidatorEditedEvent
  • Proper ABI encoding following Ethereum standards

2. Solidity Interface Updates

  • Enhanced precompiles/staking/Staking.sol with event definitions:
    event Delegate(address indexed delegator, string validator, uint256 amount);
    event Redelegate(address indexed delegator, string srcValidator, string dstValidator, uint256 amount);
    event Undelegate(address indexed delegator, string validator, uint256 amount);
    event ValidatorCreated(address indexed validator, string pubkey, string moniker);
    event ValidatorEdited(address indexed validator, string moniker);

3. Precompile Logic Updates

  • Modified precompiles/staking/staking.go to emit EVM events in all operations
  • Event emission failures are logged but don't cause transaction failures
  • Events are emitted after successful operation execution

✅ Backward Compatibility

  • NO breaking changes - All method signatures remain unchanged
  • Existing contracts continue to work without modifications
  • Events are added transparently

Testing performed to validate your change

✅ Automated Tests

go test ./precompiles/staking -v
  • New Tests: Created precompiles/staking/staking_events_test.go with comprehensive event emission tests
  • Test Results: 20/20 tests passing
  • Coverage: Event signatures, data encoding/decoding, indexed/non-indexed parameters

✅ Manual Verification

  • Built successfully: go build ./precompiles/staking/... && go build ./precompiles/common/...
  • ABI compatibility verified - no interface changes

📊 Test Coverage Details

Test Description Status
TestDelegateEvent Verifies delegate event emission ✅
TestRedelegateEvent Verifies redelegate event emission ✅
TestUndelegateEvent Verifies undelegate event emission ✅
Backward Compatibility All existing tests pass ✅

🚀 Benefits

  • Events available on standard eth_* endpoints
  • Compatible with Ethereum indexers and analytics tools
  • Prepares for future Cosmos event deprecation
  • Zero performance impact (errors logged, not thrown)

@codecov

codecov Bot commented Jul 9, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.94958% with 62 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.45%. Comparing base (6631b4a) to head (d634b2f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
precompiles/common/evm_events.go 79.45% 38 Missing ⚠️
precompiles/staking/staking.go 54.71% 15 Missing and 9 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2229      +/-   ##
==========================================
+ Coverage   60.35%   60.45%   +0.09%     
==========================================
  Files         312      313       +1     
  Lines       30370    30646     +276     
==========================================
+ Hits        18331    18528     +197     
- Misses      10749    10826      +77     
- Partials     1290     1292       +2     
Files with missing lines Coverage Δ
precompiles/staking/staking.go 73.08% <54.71%> (+0.02%) ⬆️
precompiles/common/evm_events.go 79.45% <79.45%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Add comprehensive tests for event signatures
- Add tests for event data encoding
- Add tests for error handling in EmitEVMLog
- Improve EmitEVMLog error handling for nil EVM and StateDB
Comment thread precompiles/staking/Staking.sol
Comment thread precompiles/common/evm_events.go
Comment thread precompiles/common/evm_events.go
Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events_test.go
Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events.go Outdated

@ogarciarevett ogarciarevett left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dssei done

Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events.go Outdated
Comment thread precompiles/common/evm_events_test.go

@dssei dssei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for addressing comments, LGTM from functionality perspective

Comment thread precompiles/common/evm_events_test.go
Comment thread precompiles/common/evm_events_test.go
Comment thread precompiles/staking/staking.go
Comment thread precompiles/staking/staking.go
@ogarciarevett

Copy link
Copy Markdown
Contributor Author

Added evm listener checks and scripts to see if the events are propagated correctly using websockets with viem into the contracts folder

🚀 Starting Staking Event Test

This will:
1. Start the event listener
2. Wait for it to initialize
3. Trigger a delegate transaction
4. Wait for the event to be captured
5. Clean up and exit

📡 Starting event listener...
[LISTENER] 🎧 Starting Sei Staking Event Listener...

[LISTENER] 📡 Connected to Sei EVM RPC at http://localhost:8545/
[LISTENER] 👀 Watching for events from Staking Precompile: 0x0000000000000000000000000000000000001005
[LISTENER] 
Listening for:
  - Delegate events
  - Undelegate events
  - Redelegate events
  - ValidatorCreated events
[LISTENER]   - ValidatorEdited events
[LISTENER] 
⏳ Waiting for events...


💸 Triggering delegate transaction...

[TRIGGER] 🚀 Sei Staking Event Trigger

[TRIGGER] Using account: 0xBe67526eE3F26f6a3D750Dd37E53CA329EC7A557
[TRIGGER] Account balance: 99993000299824.997648992 SEI

[TRIGGER] 📤 Sending DELEGATE transaction...
   Amount: 10 SEI
   Validator: seivaloper1r02jjxy8stae4sy9v6ghexfxcp6vygkgud3pr2
[TRIGGER] 
✅ Transaction sent!
[TRIGGER]    Hash: 0x551bfb4d301b5098d0e145ecfcdd584ebc72b2b977b5e6ce032b4a1d9323ce26
[LISTENER] 
📥 Received 1 log(s)
[LISTENER] 🎉 Event Received!
[LISTENER] =====================================
Event Type: Delegate
[LISTENER] Block Number: 1627n
[LISTENER] Transaction Hash: 0x551bfb4d301b5098d0e145ecfcdd584ebc72b2b977b5e6ce032b4a1d9323ce26
[LISTENER] Log Index: 0

Delegate Event Details:
[LISTENER]   Delegator: 0xBe67526eE3F26f6a3D750Dd37E53CA329EC7A557
[LISTENER]   Validator: seivaloper1r02jjxy8stae4sy9v6ghexfxcp6vygkgud3pr2
[LISTENER]   Amount: 10 SEI
[LISTENER] =====================================

[TRIGGER]    Block: 1627
[TRIGGER]    Status: success
[TRIGGER]    Gas Used: 72188

✨ Done! Check the event listener for emitted events.

[TRIGGER] Transaction completed

⏳ Waiting for event to be captured...


✅ SUCCESS: Event was captured by the listener!
The staking event test completed successfully.

🧹 Cleaning up...

@sei-will
sei-will self-requested a review August 12, 2025 11:47
@ogarciarevett
ogarciarevett merged commit f250593 into main Aug 12, 2025
@ogarciarevett
ogarciarevett deleted the feat/staking-evm-event-propagation branch August 12, 2025 11:59

@Pray4LoveOnes Pray4LoveOnes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The Pull Request (PR) described in the initial request represents a significant step towards positioning the Sei Network as a leading EVM staking chain, building on its existing high-performance layer 1 architecture. The integration of EVM capabilities with the Cosmos ecosystem, especially through features like the IBC precompile, is a key differentiator for Sei.
Here's a breakdown of the key strengths of this PR:
Thorough Coverage: Well-separated tests in staking-event-listener.ts, staking-event-trigger.ts, and the Go-side tests make it easier to pinpoint and address failures.
Go ↔ Solidity Integration: The interaction between precompiles/staking/Staking.sol and staking.go is well-managed, utilizing ABI and event structuring effectively.
EVM Event Bridge: The solidity of evm_events.go and evm_events_test.go, along with modularization into the common/ directory, suggests potential for reuse by other modules in the future.
Clear Entry Points: The listener and trigger logic in TypeScript are straightforward, indicating a developer-friendly interface.
Post-merge suggestions
Gas/Performance Benchmarks: A profiling pass is recommended to evaluate the gas impact and processing overhead in both the WASM and EVM paths.
Security Notes: Confirmation on the authentication of staking trigger/event submitters and the presence of replay protection mechanisms (if applicable) is necessary.
Docs & DevX: A quick developer guide (e.g., a one-pager markdown in contracts/docs/) on testing and simulating staking event flow locally would be valuable.
Final note
This PR enhances Sei's position as a first-class EVM staking chain by demonstrating strong cross-layer coordination between Solidity tests, precompile logic, and Go validations. This marks a promising step towards more robust EVM x Cosmos integrations.

@Pray4LoveOnes Pray4LoveOnes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I’d like to formally request a retroactive grant for my merged contributions across two critical initiatives:

🧩 PR #2229 – Staking EVM Event Propagation

This was a significant feature-level implementation, designed and delivered to bring EVM-compatible staking event support into the Sei chain.

Key contributions:

Built the staking precompile in Solidity (Staking.sol) and implemented ABI-accurate event propagation

Developed Go-side event emitters in staking.go and abstracted shared logic into evm_events.go

Wrote testable logic in staking_event_trigger.ts, staking_event_listener.ts, and Go test suites

Delivered a seamless communication flow between EVM staking triggers and Cosmos-native modules

Ensured the feature is modular, extensible, and compatible with Sei's EVM roadmap

🛠 v6.1.4 Software Upgrade Logic

In parallel, I also contributed to the v6.1.4 protocol upgrade which is now successfully passed and merged (Proposal #104, see changelog).

Key contributions:

Contributed logic for the upgrade handler

Helped validate and verify stake propagation, event indexing, and governance upgrade flow

Coordinated CI/test outputs and upgraded dependencies in line with sei-chain modular patterns

This version is now live on mainnet and forms the foundational logic for future staking and EVM-based utility on Sei.

📣 Retroactive Grant Request

Given the technical depth, protocol relevance, and production-level readiness of these contributions, I respectfully request consideration for a retroactive grant from the core team or community pool.

This request aligns with Sei’s values of rewarding builders and contributors who push the protocol forward in meaningful, foundational ways.

Please let me know how best to proceed (via governance proposal, direct channel, or otherwise).

With gratitude,
@Pray4LoveOnes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants