mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
make the chainid an extra parameter
This commit is contained in:
parent
659035036d
commit
8a73d64f5e
6 changed files with 32 additions and 88 deletions
|
|
@ -7,6 +7,7 @@ Keeper command is a specialized tool for validating stateless execution of Ether
|
|||
The keeper reads an RLP-encoded payload containing:
|
||||
- A block to execute
|
||||
- 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.
|
||||
|
||||
|
|
@ -19,10 +20,7 @@ cmd/keeper/
|
|||
├── main.go # Main execution logic
|
||||
├── getpayload_example.go # Example implementation with embedded data
|
||||
├── 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
|
||||
|
|
@ -41,14 +39,6 @@ import (
|
|||
// ... 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
|
||||
func getInput() []byte {
|
||||
// Your platform-specific code to retrieve the RLP-encoded payload
|
||||
|
|
@ -70,14 +60,7 @@ func getInput() []byte {
|
|||
### 2. Build for Your Platform
|
||||
|
||||
```bash
|
||||
# Build with specific platform and chain configuration
|
||||
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
|
||||
go build -tags "myplatform" ./cmd/keeper
|
||||
```
|
||||
|
||||
## Payload Structure
|
||||
|
|
@ -98,17 +81,12 @@ See `getpayload_example.go` for a complete example with embedded Hoodi block dat
|
|||
|
||||
```bash
|
||||
# Build example with different chain configurations
|
||||
go build -tags "example hoodi" ./cmd/keeper # Example with Hoodi config (default for example)
|
||||
go build -tags "example mainnet" ./cmd/keeper # Example with mainnet config
|
||||
go build -tags "example sepolia" ./cmd/keeper # Example with Sepolia config
|
||||
go build -tags "example" ./cmd/keeper
|
||||
```
|
||||
|
||||
### Ziren zkVM Implementation
|
||||
Build for the Ziren zkVM platform:
|
||||
Build for the Ziren zkVM platform, which is a MIPS ISA-based zkvm:
|
||||
|
||||
```bash
|
||||
# For MIPS architecture (typical for zkVM)
|
||||
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
|
||||
GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build -tags "ziren" ./cmd/keeper
|
||||
```
|
||||
|
|
|
|||
|
|
@ -14,13 +14,25 @@
|
|||
// 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 && !sepolia
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/ethereum/go-ethereum/params"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// getChainConfig returns the Ethereum mainnet chain configuration.
|
||||
func getChainConfig() *params.ChainConfig {
|
||||
return params.MainnetChainConfig
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
)
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/stateless"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"github.com/ethereum/go-ethereum/rlp"
|
||||
)
|
||||
|
||||
|
|
@ -63,7 +64,6 @@ var witnessRlp []byte
|
|||
//go:embed 1192c3_block.rlp
|
||||
var blockRlp []byte
|
||||
|
||||
|
||||
// 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
|
||||
// that contains the witness and the block.
|
||||
|
|
@ -88,6 +88,7 @@ func getInput() []byte {
|
|||
}
|
||||
|
||||
payload := Payload{
|
||||
ChainID: params.HoodiChainConfig.ChainID.Uint64(),
|
||||
Block: &block,
|
||||
Witness: witness,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
// Payload represents the input data for stateless execution containing
|
||||
// a block and its associated witness data for verification.
|
||||
type Payload struct {
|
||||
ChainID uint64
|
||||
Block *types.Block
|
||||
Witness *stateless.Witness
|
||||
}
|
||||
|
|
@ -39,7 +40,11 @@ func main() {
|
|||
var payload 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{}
|
||||
|
||||
crossStateRoot, crossReceiptRoot, err := core.ExecuteStateless(chainConfig, vmConfig, payload.Block, payload.Witness)
|
||||
|
|
|
|||
Loading…
Reference in a new issue