make the chainid an extra parameter

This commit is contained in:
Guillaume Ballet 2025-09-12 06:21:48 -04:00
parent 659035036d
commit 8a73d64f5e
6 changed files with 32 additions and 88 deletions

View file

@ -7,6 +7,7 @@ Keeper command is a specialized tool for validating stateless execution of Ether
The keeper reads an RLP-encoded payload containing: The keeper reads an RLP-encoded payload containing:
- A block to execute - A block to execute
- A witness with the necessary state data - A witness with the necessary state data
- A chainID
It then executes the block statelessly and validates that the computed state root and receipt root match the values in the block header. It then executes the block statelessly and validates that the computed state root and receipt root match the values in the block header.
@ -19,10 +20,7 @@ cmd/keeper/
├── main.go # Main execution logic ├── main.go # Main execution logic
├── getpayload_example.go # Example implementation with embedded data ├── getpayload_example.go # Example implementation with embedded data
├── getpayload_ziren.go # Ziren zkVM implementation ├── getpayload_ziren.go # Ziren zkVM implementation
├── chainconfig_mainnet.go # Mainnet chain configuration └── ...
├── chainconfig_sepolia.go # Sepolia chain configuration
├── chainconfig_hoodi.go # Hoodi chain configuration
└── README.md # This file
``` ```
## Creating a Custom Platform Implementation ## Creating a Custom Platform Implementation
@ -41,14 +39,6 @@ import (
// ... other imports as needed // ... other imports as needed
) )
// getChainConfig returns the chain configuration for this platform
func getChainConfig() *params.ChainConfig {
// Return the appropriate chain config for your platform
// Examples: params.MainnetChainConfig, params.SepoliaChainConfig,
// or a custom configuration
return params.MainnetChainConfig
}
// getInput returns the RLP-encoded payload // getInput returns the RLP-encoded payload
func getInput() []byte { func getInput() []byte {
// Your platform-specific code to retrieve the RLP-encoded payload // Your platform-specific code to retrieve the RLP-encoded payload
@ -70,14 +60,7 @@ func getInput() []byte {
### 2. Build for Your Platform ### 2. Build for Your Platform
```bash ```bash
# Build with specific platform and chain configuration go build -tags "myplatform" ./cmd/keeper
go build -tags "myplatform mainnet" ./cmd/keeper
# Available chain configurations:
# - mainnet: Ethereum mainnet
# - sepolia: Sepolia testnet
# - hoodi: Hoodi testnet
# If no chain tag is specified, defaults to mainnet
``` ```
## Payload Structure ## Payload Structure
@ -98,17 +81,12 @@ See `getpayload_example.go` for a complete example with embedded Hoodi block dat
```bash ```bash
# Build example with different chain configurations # Build example with different chain configurations
go build -tags "example hoodi" ./cmd/keeper # Example with Hoodi config (default for example) go build -tags "example" ./cmd/keeper
go build -tags "example mainnet" ./cmd/keeper # Example with mainnet config
go build -tags "example sepolia" ./cmd/keeper # Example with Sepolia config
``` ```
### Ziren zkVM Implementation ### Ziren zkVM Implementation
Build for the Ziren zkVM platform: Build for the Ziren zkVM platform, which is a MIPS ISA-based zkvm:
```bash ```bash
# For MIPS architecture (typical for zkVM) GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -tags "ziren" ./cmd/keeper
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -tags "ziren mainnet" ./cmd/keeper
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -tags "ziren sepolia" ./cmd/keeper
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -tags "ziren hoodi" ./cmd/keeper
``` ```

View file

@ -14,13 +14,25 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build !hoodi && !sepolia
package main package main
import "github.com/ethereum/go-ethereum/params" import (
"fmt"
// getChainConfig returns the Ethereum mainnet chain configuration. "github.com/ethereum/go-ethereum/params"
func getChainConfig() *params.ChainConfig { )
return params.MainnetChainConfig
// getChainConfig returns the appropriate chain configuration based on the chainID.
// Returns an error for unsupported chain IDs.
func getChainConfig(chainID uint64) (*params.ChainConfig, error) {
switch chainID {
case 0, params.MainnetChainConfig.ChainID.Uint64():
return params.MainnetChainConfig, nil
case params.SepoliaChainConfig.ChainID.Uint64():
return params.SepoliaChainConfig, nil
case params.HoodiChainConfig.ChainID.Uint64():
return params.HoodiChainConfig, nil
default:
return nil, fmt.Errorf("unsupported chain ID: %d", chainID)
}
} }

View file

@ -1,26 +0,0 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build hoodi
package main
import "github.com/ethereum/go-ethereum/params"
// getChainConfig returns the Hoodi testnet chain configuration.
func getChainConfig() *params.ChainConfig {
return params.HoodiChainConfig
}

View file

@ -1,26 +0,0 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build sepolia
package main
import "github.com/ethereum/go-ethereum/params"
// getChainConfig returns the Sepolia testnet chain configuration.
func getChainConfig() *params.ChainConfig {
return params.SepoliaChainConfig
}

View file

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/stateless" "github.com/ethereum/go-ethereum/core/stateless"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
@ -63,7 +64,6 @@ var witnessRlp []byte
//go:embed 1192c3_block.rlp //go:embed 1192c3_block.rlp
var blockRlp []byte var blockRlp []byte
// getInput is a platform-specific function that will recover the input payload // getInput is a platform-specific function that will recover the input payload
// and returns it as a slice. It is expected to be an RLP-encoded Payload structure // and returns it as a slice. It is expected to be an RLP-encoded Payload structure
// that contains the witness and the block. // that contains the witness and the block.
@ -88,6 +88,7 @@ func getInput() []byte {
} }
payload := Payload{ payload := Payload{
ChainID: params.HoodiChainConfig.ChainID.Uint64(),
Block: &block, Block: &block,
Witness: witness, Witness: witness,
} }

View file

@ -30,6 +30,7 @@ import (
// Payload represents the input data for stateless execution containing // Payload represents the input data for stateless execution containing
// a block and its associated witness data for verification. // a block and its associated witness data for verification.
type Payload struct { type Payload struct {
ChainID uint64
Block *types.Block Block *types.Block
Witness *stateless.Witness Witness *stateless.Witness
} }
@ -39,7 +40,11 @@ func main() {
var payload Payload var payload Payload
rlp.DecodeBytes(input, &payload) rlp.DecodeBytes(input, &payload)
chainConfig := getChainConfig() chainConfig, err := getChainConfig(payload.ChainID)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to get chain config: %v\n", err)
os.Exit(13)
}
vmConfig := vm.Config{} vmConfig := vm.Config{}
crossStateRoot, crossReceiptRoot, err := core.ExecuteStateless(chainConfig, vmConfig, payload.Block, payload.Witness) crossStateRoot, crossReceiptRoot, err := core.ExecuteStateless(chainConfig, vmConfig, payload.Block, payload.Witness)