Skip to content

Commit

Permalink
Add unverifiable range to custom-networks (#1659)
Browse files Browse the repository at this point in the history
* Add unverifiable range to custom-networks
  • Loading branch information
rianhughes authored Jan 16, 2024
1 parent d9bcd03 commit 8f17795
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
16 changes: 13 additions & 3 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
cnL1ChainIDF = "cn-l1-chain-id"
cnL2ChainIDF = "cn-l2-chain-id"
cnCoreContractAddressF = "cn-core-contract-address"
cnUnverifiableRangeF = "cn-unverifiable-range"

defaultConfig = ""
defaulHost = "localhost"
Expand Down Expand Up @@ -121,6 +122,7 @@ const (
networkCustomL1ChainIDUsage = "Custom network L1 chain id."
networkCustomL2ChainIDUsage = "Custom network L2 chain id."
networkCustomCoreContractAddressUsage = "Custom network core contract address."
networkCustomUnverifiableRange = "Custom network range of blocks to skip hash verifications (e.g. `0,100`)."
pprofUsage = "Enables the pprof endpoint on the default port."
pprofHostUsage = "The interface on which the pprof HTTP server will listen for requests."
pprofPortUsage = "The port on which the pprof HTTP server will listen for requests."
Expand Down Expand Up @@ -237,8 +239,13 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
if v.IsSet(cnNameF) {
l1ChainID, ok := new(big.Int).SetString(v.GetString(cnL1ChainIDF), 0)
if !ok {
return fmt.Errorf("invalid L1 chain id %s", v.GetString(cnL1ChainIDF))
return fmt.Errorf("invalid %s id %s", cnL1ChainIDF, v.GetString(cnL1ChainIDF))
}
unverifRange := v.GetIntSlice(cnUnverifiableRangeF)
if len(unverifRange) != 2 || unverifRange[0] < 0 || unverifRange[1] < 0 {
return fmt.Errorf("invalid %s:%v, must be uint array of length 2 (e.g. `0,100`)", cnUnverifiableRangeF, unverifRange)
}

config.Network = utils.Network{
Name: v.GetString(cnNameF),
FeederURL: v.GetString(cnFeederURLF),
Expand All @@ -247,7 +254,8 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
L2ChainID: v.GetString(cnL2ChainIDF),
CoreContractAddress: common.HexToAddress(v.GetString(cnCoreContractAddressF)),
BlockHashMetaInfo: &utils.BlockHashMetaInfo{
First07Block: 0,
First07Block: 0,
UnverifiableRange: []uint64{uint64(unverifRange[0]), uint64(unverifRange[1])},
},
}
}
Expand All @@ -269,6 +277,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
defaultLogLevel := utils.INFO
defaultNetwork := utils.Mainnet
defaultMaxVMs := 3 * runtime.GOMAXPROCS(0)
defaultCNUnverifiableRange := []int{} // Uint64Slice is not supported in Flags()

junoCmd.Flags().StringVar(&cfgFile, configF, defaultConfig, configFlagUsage)
junoCmd.Flags().Var(&defaultLogLevel, logLevelF, logLevelFlagUsage)
Expand All @@ -286,6 +295,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
junoCmd.Flags().String(cnL1ChainIDF, defaultCNL1ChainID, networkCustomL1ChainIDUsage)
junoCmd.Flags().String(cnL2ChainIDF, defaultCNL2ChainID, networkCustomL2ChainIDUsage)
junoCmd.Flags().String(cnCoreContractAddressF, defaultCNCoreContractAddressStr, networkCustomCoreContractAddressUsage)
junoCmd.Flags().IntSlice(cnUnverifiableRangeF, defaultCNUnverifiableRange, networkCustomUnverifiableRange)
junoCmd.Flags().String(ethNodeF, defaultEthNode, ethNodeUsage)
junoCmd.Flags().Bool(pprofF, defaultPprof, pprofUsage)
junoCmd.Flags().String(pprofHostF, defaulHost, pprofHostUsage)
Expand All @@ -308,7 +318,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
junoCmd.Flags().Uint(dbCacheSizeF, defaultCacheSizeMb, dbCacheSizeUsage)
junoCmd.Flags().String(gwAPIKeyF, defaultGwAPIKey, gwAPIKeyUsage)
junoCmd.Flags().Int(dbMaxHandlesF, defaultMaxHandles, dbMaxHandlesUsage)
junoCmd.MarkFlagsRequiredTogether(cnNameF, cnFeederURLF, cnGatewayURLF, cnL1ChainIDF, cnL2ChainIDF, cnCoreContractAddressF)
junoCmd.MarkFlagsRequiredTogether(cnNameF, cnFeederURLF, cnGatewayURLF, cnL1ChainIDF, cnL2ChainIDF, cnCoreContractAddressF, cnUnverifiableRangeF) //nolint:lll
junoCmd.MarkFlagsMutuallyExclusive(networkF, cnNameF)

return junoCmd
Expand Down
5 changes: 4 additions & 1 deletion cmd/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ func TestConfigPrecedence(t *testing.T) {
L1ChainID: new(big.Int).SetUint64(1),
CoreContractAddress: defaultCoreContractAddress,
BlockHashMetaInfo: &utils.BlockHashMetaInfo{
First07Block: 0,
First07Block: 0,
UnverifiableRange: []uint64{0, 10},
},
}
defaultPprof := false
Expand Down Expand Up @@ -76,6 +77,7 @@ func TestConfigPrecedence(t *testing.T) {
"--db-path", "/home/.juno", "--pprof", "--db-cache-size", "8",
"--cn-name", "custom", "--cn-feeder-url", "awesome_feeder_url", "--cn-gateway-url", "awesome_gateway_url",
"--cn-l1-chain-id", "0x1", "--cn-l2-chain-id", "SN_AWESOME",
"--cn-unverifiable-range", "0,10",
"--cn-core-contract-address", "0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4",
},
expectedConfig: &node.Config{
Expand Down Expand Up @@ -119,6 +121,7 @@ cn-gateway-url: awesome_gateway_url
cn-l2-chain-id: SN_AWESOME
cn-l1-chain-id: 0x1
cn-core-contract-address: 0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4
cn-unverifiable-range: [0,10]
`,
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
Expand Down
21 changes: 12 additions & 9 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ func VerifyBlockHash(b *Block, network *utils.Network) (*BlockCommitments, error
}
}

if err := VerifyTransactions(b.Transactions, network, b.ProtocolVersion); err != nil {
return nil, err
}

metaInfo := network.BlockHashMetaInfo
unverifiableRange := metaInfo.UnverifiableRange

skipVerification := unverifiableRange != nil && b.Number >= unverifiableRange[0] && b.Number <= unverifiableRange[1] //nolint:gocritic

if !skipVerification {
if err := VerifyTransactions(b.Transactions, network, b.ProtocolVersion); err != nil {
return nil, err
}
}

fallbackSeqAddresses := []*felt.Felt{&felt.Zero}
if metaInfo.FallBackSequencerAddress != nil {
fallbackSeqAddresses = append(fallbackSeqAddresses, metaInfo.FallBackSequencerAddress)
Expand All @@ -91,12 +96,10 @@ func VerifyBlockHash(b *Block, network *utils.Network) (*BlockCommitments, error

if hash.Equal(b.Hash) {
return commitments, nil
} else if unverifiableRange != nil {
} else if skipVerification {
// Check if the block number is in the unverifiable range
if b.Number >= unverifiableRange[0] && b.Number <= unverifiableRange[1] {
// If so, return success
return commitments, nil
}
// If so, return success
return commitments, nil
}
}

Expand Down

0 comments on commit 8f17795

Please sign in to comment.