Skip to content

Conversation

@felipemadero
Copy link
Collaborator

@felipemadero felipemadero commented Nov 19, 2025

Why this should be merged

This PR implements ERC20 token-based Proof of Stake validator management as an alternative to native token staking. This provides more flexibility for L1 validator economics by allowing custom tokens to be used for staking instead of being limited to native tokens.

Key improvements:

  • Adds support for ERC20 token staking in validator managers
  • Improves epoch handling with proper timing and dummy transfers to ensure P-Chain/L1 synchronization
  • Fixes reward calculator initialization for validator managers on the L1, taking it out of genesis

How this works

ERC20 PoS Implementation:

  • Introduces new MintableERC20 contract for staking tokens with unlimited minting capability
  • Adds PoSERC20ValidatorManager contract deployment and initialization
  • Implements token deployment flow with ownership transfer to validator manager
  • Extends validator registration/weight change flows to support ERC20 token staking

Validator Management Type Refactoring:

  • Splits validator management into three types: PoA, PoS Native, and PoS ERC20
  • Replaces --proof-of-stake with --proof-of-stake-native and --proof-of-stake-erc20 flags
  • Updates all validator operations to handle ERC20-specific requirements

Validator Manager Improvements:

  • Adds proper epoch synchronization with ProposerVMEpochDuration constant (30s)
  • Implements dummy P-Chain transfers to advance epochs when needed for message signing
  • Fixes Fuji height gathering for external validator managers
  • Removes genesis-based reward calculator (now deployed at validator manager initialization)
  • Adds reward calculator deployment for external validator managers

CLI Enhancements:

  • Interactive ERC20 token deployment flow with options to provide existing token or deploy new one
  • Adds reward calculator deployment and configuration
  • Improves error handling and user guidance for validator management setup

How this was tested

  • E2E test suites:
    • addRemoveValidatorPoSNative - Tests native token staking flow (L1 manager)
    • addRemoveValidatorPoSERC20 - Tests ERC20 token staking flow (both L1 and External managers)

Update sendMsg to use the new SimulateTransaction function which uses
standard eth_call instead of debug_traceTransaction. When a transaction
fails, extract and display the error selector and revert data to help
users debug the issue.

Update SDK dependency to version that eliminates debug RPC method dependency,
ensuring all CLI flows work with any standard EVM RPC endpoint.
@felipemadero felipemadero changed the base branch from main to extract-solidity-errors-from-rpc November 20, 2025 11:43
@felipemadero felipemadero changed the title Erc20 vmc Add ERC20 token-based Proof of Stake validator management Nov 20, 2025
When gas estimation was enforced (after removing debug trace fallback),
validator removal began failing with "min stake duration not passed" even
though system time had passed the threshold. This occurred because
eth_estimateGas uses the current block timestamp, which can lag behind
system time, especially right after the minimum stake duration expires.

The contract check in StakingManager sets validator.endTime to
block.timestamp during initiateValidatorRemoval, then immediately checks:
  if (block.timestamp < startTime + minStakeDuration) revert

During gas estimation, this uses the CURRENT block's timestamp. When the
actual transaction would be mined in a NEW block with a LATER timestamp,
it would succeed. But with gas estimation now enforced, the transaction
never gets submitted.

Solution: Before attempting removal, check the current blockchain timestamp.
If it hasn't passed the threshold yet, create a dummy block (via self-transfer
with 0 value) to advance the blockchain time. This ensures gas estimation
will succeed using the updated block timestamp.

This fix is necessary for the new SDK behavior that enforces gas estimation
errors instead of falling back to a default gas limit.
Base automatically changed from extract-solidity-errors-from-rpc to main November 26, 2025 16:53
@felipemadero felipemadero merged commit 30795ec into main Dec 23, 2025
64 checks passed
@felipemadero felipemadero deleted the erc20-vmc branch December 23, 2025 17:44
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