Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host: replace sequencer ID config with sequencer p2p address #1885

Merged
merged 5 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ jobs:
-message_bus_contract_addr=${{needs.build.outputs.MSG_BUS_CONTRACT_ADDR}} \
-l1_start=${{needs.build.outputs.L1_START_HASH}} \
-private_key=${{ secrets[matrix.node_pk_lookup] }} \
-sequencer_id=${{ vars.ACCOUNT_ADDR_NODE_0 }} \
-sequencer_addr=obscuronode-0-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_public_p2p_addr=obscuronode-${{ matrix.host_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_p2p_port=10000 \
-enclave_docker_image=${{ vars.L2_ENCLAVE_DOCKER_BUILD_TAG }} \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-testnet-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ jobs:
-message_bus_contract_addr=${{ github.event.inputs.MSG_BUS_CONTRACT_ADDR }} \
-l1_start=${{ github.event.inputs.L1_START_HASH }} \
-private_key=${{ secrets.ADD_NEW_NODE_PRIVATE_KEY }} \
-sequencer_id=${{ vars.ACCOUNT_ADDR_NODE_0 }} \
-sequencer_addr=obscuronode-0-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_public_p2p_addr=obscuronode-${{ github.event.inputs.node_id }}-${{ github.event.inputs.testnet_type }}-${{ GITHUB.RUN_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_p2p_port=10000 \
-enclave_docker_image=${{ vars.L2_ENCLAVE_DOCKER_BUILD_TAG }} \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/manual-upgrade-testnet-l2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
-host_id=${{ vars[matrix.node_addr_lookup] }} \
-l1_ws_url=${{ secrets[matrix.node_l1_ws_lookup] }} \
-private_key=${{ secrets[matrix.node_pk_lookup] }} \
-sequencer_id=${{ vars.ACCOUNT_ADDR_NODE_0 }} \
-sequencer_addr=obscuronode-0-${{ github.event.inputs.testnet_type }}-${{ needs.build.outputs.VM_BUILD_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_public_p2p_addr=obscuronode-${{ matrix.host_id }}-${{ github.event.inputs.testnet_type }}-${{ needs.build.outputs.VM_BUILD_NUMBER }}.uksouth.cloudapp.azure.com:10000 \
-host_p2p_port=10000 \
-enclave_docker_image=${{ vars.L2_ENCLAVE_DOCKER_BUILD_TAG }} \
Expand Down
83 changes: 26 additions & 57 deletions contracts/generated/ManagementContract/ManagementContract.go

Large diffs are not rendered by default.

17 changes: 4 additions & 13 deletions contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ contract ManagementContract is Initializable, OwnableUpgradeable {

// mapping of enclaveID to whether it is attested
mapping(address => bool) private attested;

// mapping of enclaveID to whether it is permissioned as a sequencer enclave
// note: the enclaveID which initialises the network secret is automatically permissioned as a sequencer.
// Beyond that, the contract owner can grant and revoke sequencer status.
mapping(address => bool) private sequencerEnclave;

// TODO - Revisit the decision to store the host addresses in the smart contract.
string[] private hostAddresses; // The addresses of all the Ten hosts on the network.

// In the near-term it is convenient to have an accessible source of truth for important contract addresses
// TODO - this is probably not appropriate long term but currently useful for testnets. Look to remove.
// We store the keys as well as the mapping for the key-value store for important contract addresses for convenience
Expand Down Expand Up @@ -96,15 +94,14 @@ contract ManagementContract is Initializable, OwnableUpgradeable {

// InitializeNetworkSecret kickstarts the network secret, can only be called once
// solc-ignore-next-line unused-param
function InitializeNetworkSecret(address _enclaveID, bytes calldata _initSecret, string memory _hostAddress, string calldata _genesisAttestation) public {
function InitializeNetworkSecret(address _enclaveID, bytes calldata _initSecret, string calldata _genesisAttestation) public {
require(!networkSecretInitialized, "network secret already initialized");

// network can no longer be initialized
networkSecretInitialized = true;

// enclave is now on the list of attested enclaves (and its host address is published for p2p)
attested[_enclaveID] = true;
hostAddresses.push(_hostAddress);

// the enclave that starts the network with this call is implicitly a sequencer so doesn't need adding
sequencerEnclave[_enclaveID] = true;
Expand All @@ -119,7 +116,7 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
// and, if valid, will respond with the Network Secret
// and mark the requesterID as attested
// @param verifyAttester Whether to ask the attester to complete a challenge (signing a hash) to prove their identity.
function RespondNetworkSecret(address attesterID, address requesterID, bytes memory attesterSig, bytes memory responseSecret, string memory hostAddress, bool verifyAttester) public {
function RespondNetworkSecret(address attesterID, address requesterID, bytes memory attesterSig, bytes memory responseSecret, bool verifyAttester) public {
// only attested enclaves can respond to Network Secret Requests
bool isEnclAttested = attested[attesterID];
require(isEnclAttested, "responding attester is not attested");
Expand All @@ -130,20 +127,14 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
// signature = f(PubKey, PrivateKey, message)
// address = f(signature, message)
// valid if attesterID = address
bytes32 calculatedHashSigned = abi.encodePacked(attesterID, requesterID, hostAddress, responseSecret).toEthSignedMessageHash();
bytes32 calculatedHashSigned = abi.encodePacked(attesterID, requesterID, responseSecret).toEthSignedMessageHash();
address recoveredAddrSignedCalculated = ECDSA.recover(calculatedHashSigned, attesterSig);

require(recoveredAddrSignedCalculated == attesterID, "calculated address and attesterID dont match");
}

// mark the requesterID enclave as an attested enclave and store its host address
attested[requesterID] = true;
// TODO - Consider whether to remove duplicates.
hostAddresses.push(hostAddress);
}

function GetHostAddresses() public view returns (string[] memory) {
return hostAddresses;
}


Expand Down
5 changes: 0 additions & 5 deletions go/common/host/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ type P2P interface {
// SubscribeForBatchRequests will register a handler to receive new batch requests from peers, returns unsubscribe func
// todo (@matt) feels a bit weird to have this in this interface since it relates to serving data rather than receiving
SubscribeForBatchRequests(handler P2PBatchRequestHandler) func()

// RefreshPeerList notifies the P2P service that its peer list might be out-of-date and it should resync
RefreshPeerList()
}

// P2PBatchHandler is an interface for receiving new batches from the P2P network as they arrive
Expand Down Expand Up @@ -111,8 +108,6 @@ type L1Publisher interface {
// PublishSecretResponse will create and publish a secret response tx to the management contract - fire and forget we don't wait for receipt
PublishSecretResponse(secretResponse *common.ProducedSecretResponse) error

FetchLatestPeersList() ([]string, error)

FetchLatestSeqNo() (*big.Int, error)

// GetImportantContracts returns a (cached) record of addresses of the important network contracts
Expand Down
1 change: 0 additions & 1 deletion go/common/query_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ type PrivateCustomQueryListTransactions struct {
type ObscuroNetworkInfo struct {
ManagementContractAddress common.Address
L1StartHash common.Hash
SequencerID common.Address
MessageBusAddress common.Address
L2MessageBusAddress common.Address
ImportantContracts map[string]common.Address // map of contract name to address
Expand Down
2 changes: 0 additions & 2 deletions go/config/enclave_cli_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const (
ProfilerEnabledFlag = "profilerEnabled"
MinGasPriceFlag = "minGasPrice"
MessageBusAddressFlag = "messageBusAddress"
SequencerIDFlag = "sequencerID"
ObscuroGenesisFlag = "obscuroGenesis"
DebugNamespaceEnabledFlag = "debugNamespaceEnabled"
MaxBatchSizeFlag = "maxBatchSize"
Expand All @@ -51,7 +50,6 @@ var EnclaveFlags = map[string]*flag.TenFlag{
SQLiteDBPathFlag: flag.NewStringFlag(SQLiteDBPathFlag, "", "Filepath for the sqlite DB persistence file (can be empty if a throwaway file in /tmp/ is acceptable or if using InMemory DB or if using attestation/EdgelessDB)"),
MinGasPriceFlag: flag.NewInt64Flag(MinGasPriceFlag, 1, "The minimum gas price for mining a transaction"),
MessageBusAddressFlag: flag.NewStringFlag(MessageBusAddressFlag, "", "The address of the L1 message bus contract owned by the management contract."),
SequencerIDFlag: flag.NewStringFlag(SequencerIDFlag, "", "The 20 bytes of the address of the sequencer for this network"),
MaxBatchSizeFlag: flag.NewUint64Flag(MaxBatchSizeFlag, 1024*55, "The maximum size a batch is allowed to reach uncompressed"),
MaxRollupSizeFlag: flag.NewUint64Flag(MaxRollupSizeFlag, 1024*64, "The maximum size a rollup is allowed to reach"),
L2BaseFeeFlag: flag.NewUint64Flag(L2BaseFeeFlag, params.InitialBaseFee, ""),
Expand Down
5 changes: 2 additions & 3 deletions go/config/enclave_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ type EnclaveConfig struct {
MinGasPrice *big.Int
// MessageBus L1 Address
MessageBusAddress gethcommon.Address
// The identity of the sequencer for the network
SequencerID gethcommon.Address
// P2P address for validators to connect to the sequencer for live batch data
SequencerP2PAddress string
// A json string that specifies the prefunded addresses at the genesis of the Obscuro network
ObscuroGenesis string
// Whether debug calls are available
Expand Down Expand Up @@ -186,7 +186,6 @@ func newConfig(flags map[string]*flag.TenFlag) (*EnclaveConfig, error) {
cfg.ProfilerEnabled = flags[ProfilerEnabledFlag].Bool()
cfg.MinGasPrice = big.NewInt(flags[MinGasPriceFlag].Int64())
cfg.MessageBusAddress = gethcommon.HexToAddress(flags[MessageBusAddressFlag].String())
cfg.SequencerID = gethcommon.HexToAddress(flags[SequencerIDFlag].String())
cfg.ObscuroGenesis = flags[ObscuroGenesisFlag].String()
cfg.DebugNamespaceEnabled = flags[DebugNamespaceEnabledFlag].Bool()
cfg.MaxBatchSize = flags[MaxBatchSizeFlag].Uint64()
Expand Down
12 changes: 6 additions & 6 deletions go/config/host_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type HostInputConfig struct {
L1RPCTimeout time.Duration
// Timeout duration for messaging between hosts.
P2PConnectionTimeout time.Duration
// P2P address of network sequencer node
SequencerP2PAddress string
// The rollup contract address on the L1 network
ManagementContractAddress gethcommon.Address
// The message bus contract address on the L1 network
Expand All @@ -63,8 +65,6 @@ type HostInputConfig struct {
ProfilerEnabled bool
// L1StartHash is the hash of the L1 block we can start streaming from for all Obscuro state (e.g. management contract deployment block)
L1StartHash gethcommon.Hash
// The ID of the obscuro sequencer node
SequencerID gethcommon.Address

// MetricsEnabled defines whether the metrics are enabled or not
MetricsEnabled bool
Expand Down Expand Up @@ -127,7 +127,7 @@ func (p HostInputConfig) ToHostConfig() *HostConfig {
ObscuroChainID: p.ObscuroChainID,
ProfilerEnabled: p.ProfilerEnabled,
L1StartHash: p.L1StartHash,
SequencerID: p.SequencerID,
SequencerP2PAddress: p.SequencerP2PAddress,
ID: gethcommon.Address{},
MetricsEnabled: p.MetricsEnabled,
MetricsHTTPPort: p.MetricsHTTPPort,
Expand Down Expand Up @@ -155,8 +155,8 @@ type HostConfig struct {
ObscuroChainID int64
// L1StartHash is the hash of the L1 block we can start streaming from for all Obscuro state (e.g. management contract deployment block)
L1StartHash gethcommon.Hash
// The ID of the obscuro sequencer node
SequencerID gethcommon.Address
// The address of the sequencer node's P2P server
SequencerP2PAddress string
// The rollup contract address on the L1 network
ManagementContractAddress gethcommon.Address
// The message bus contract address on the L1 network
Expand Down Expand Up @@ -263,7 +263,7 @@ func DefaultHostParsedConfig() *HostInputConfig {
ObscuroChainID: 443,
ProfilerEnabled: false,
L1StartHash: common.L1BlockHash{}, // this hash will not be found, host will log a warning and then stream from L1 genesis
SequencerID: gethcommon.BytesToAddress([]byte("")),
SequencerP2PAddress: "127.0.0.1:10000",
MetricsEnabled: true,
MetricsHTTPPort: 14000,
UseInMemoryDB: true,
Expand Down
4 changes: 1 addition & 3 deletions go/enclave/components/sigverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ import (
)

type SignatureValidator struct {
SequencerID gethcommon.Address
attestedKey *ecdsa.PublicKey
storage storage.Storage
}

func NewSignatureValidator(seqID gethcommon.Address, storage storage.Storage) (*SignatureValidator, error) {
func NewSignatureValidator(storage storage.Storage) (*SignatureValidator, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This obviously v dodgy atm. Working on PR to validate the sigs against the sequencer enclave ID(s) from management contract.

// todo (#718) - sequencer identities should be retrieved from the L1 management contract
return &SignatureValidator{
SequencerID: seqID,
storage: storage,
attestedKey: nil,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions go/enclave/enclave.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func NewEnclave(
gasOracle := gas.NewGasOracle()
blockProcessor := components.NewBlockProcessor(storage, crossChainProcessors, gasOracle, logger)
batchExecutor := components.NewBatchExecutor(storage, *config, gethEncodingService, crossChainProcessors, genesis, gasOracle, chainConfig, config.GasBatchExecutionLimit, logger)
sigVerifier, err := components.NewSignatureValidator(config.SequencerID, storage)
sigVerifier, err := components.NewSignatureValidator(storage)
registry := components.NewBatchRegistry(storage, logger)
rProducer := components.NewRollupProducer(enclaveKey.EnclaveID(), storage, registry, logger)
if err != nil {
Expand Down Expand Up @@ -212,7 +212,7 @@ func NewEnclave(
blockchain,
)
} else {
service = nodetype.NewValidator(blockProcessor, batchExecutor, registry, rConsumer, chainConfig, config.SequencerID, storage, sigVerifier, mempool, logger)
service = nodetype.NewValidator(blockProcessor, batchExecutor, registry, rConsumer, chainConfig, storage, sigVerifier, mempool, logger)
}

chain := l2chain.NewChain(
Expand Down
5 changes: 1 addition & 4 deletions go/enclave/nodetype/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ten-protocol/go-ten/go/common/log"
"github.com/ten-protocol/go-ten/go/enclave/storage"

gethcommon "github.com/ethereum/go-ethereum/common"
gethlog "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ten-protocol/go-ten/go/common"
Expand All @@ -30,15 +29,14 @@ type obsValidator struct {

chainConfig *params.ChainConfig

sequencerID gethcommon.Address
storage storage.Storage
sigValidator *components.SignatureValidator
mempool *txpool.TxPool

logger gethlog.Logger
}

func NewValidator(consumer components.L1BlockProcessor, batchExecutor components.BatchExecutor, registry components.BatchRegistry, rollupConsumer components.RollupConsumer, chainConfig *params.ChainConfig, sequencerID gethcommon.Address, storage storage.Storage, sigValidator *components.SignatureValidator, mempool *txpool.TxPool, logger gethlog.Logger) ObsValidator {
func NewValidator(consumer components.L1BlockProcessor, batchExecutor components.BatchExecutor, registry components.BatchRegistry, rollupConsumer components.RollupConsumer, chainConfig *params.ChainConfig, storage storage.Storage, sigValidator *components.SignatureValidator, mempool *txpool.TxPool, logger gethlog.Logger) ObsValidator {
startMempool(registry, mempool)

return &obsValidator{
Expand All @@ -47,7 +45,6 @@ func NewValidator(consumer components.L1BlockProcessor, batchExecutor components
batchRegistry: registry,
rollupConsumer: rollupConsumer,
chainConfig: chainConfig,
sequencerID: sequencerID,
storage: storage,
sigValidator: sigValidator,
mempool: mempool,
Expand Down
3 changes: 0 additions & 3 deletions go/ethadapter/l1_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type L1RespondSecretTx struct {
RequesterID gethcommon.Address
AttesterID gethcommon.Address
AttesterSig []byte
HostAddress string
}

type L1SetImportantContractsTx struct {
Expand All @@ -43,7 +42,6 @@ func (l *L1RespondSecretTx) Sign(privateKey *ecdsa.PrivateKey) *L1RespondSecretT
var data []byte
data = append(data, l.AttesterID.Bytes()...)
data = append(data, l.RequesterID.Bytes()...)
data = append(data, l.HostAddress...)
data = append(data, string(l.Secret)...)

ethereumMessageHash := func(data []byte) []byte {
Expand Down Expand Up @@ -71,6 +69,5 @@ type L1RequestSecretTx struct {
type L1InitializeSecretTx struct {
EnclaveID *gethcommon.Address
InitialSecret []byte
HostAddress string
Attestation common.EncodedAttestationReport
}
12 changes: 0 additions & 12 deletions go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (c *contractLibImpl) CreateRespondSecret(tx *ethadapter.L1RespondSecretTx,
tx.RequesterID,
tx.AttesterSig,
tx.Secret,
tx.HostAddress,
verifyAttester,
)
if err != nil {
Expand All @@ -186,7 +185,6 @@ func (c *contractLibImpl) CreateInitializeSecret(tx *ethadapter.L1InitializeSecr
InitializeSecretMethod,
tx.EnclaveID,
tx.InitialSecret,
tx.HostAddress,
base64EncodeToString(tx.Attestation),
)
if err != nil {
Expand Down Expand Up @@ -383,20 +381,10 @@ func (c *contractLibImpl) unpackRespondSecretTx(tx *types.Transaction, method *a
c.logger.Crit("could not decode responseSecret data")
}

hostAddressData, found := contractCallData["hostAddress"]
if !found {
c.logger.Crit("call data not found for hostAddress")
}
hostAddressString, ok := hostAddressData.(string)
if !ok {
c.logger.Crit("could not decode hostAddress data")
}

return &ethadapter.L1RespondSecretTx{
AttesterID: attesterAddr,
RequesterID: requesterAddr,
Secret: responseSecretBytes[:],
HostAddress: hostAddressString,
}
}

Expand Down
8 changes: 4 additions & 4 deletions go/host/container/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type HostConfigToml struct {
ObscuroChainID int64
ProfilerEnabled bool
L1StartHash string
SequencerID string
SequencerP2PAddress string
MetricsEnabled bool
MetricsHTTPPort uint
UseInMemoryDB bool
Expand Down Expand Up @@ -83,7 +83,7 @@ func ParseConfig() (*config.HostInputConfig, error) {
privateKeyStr := flag.String(privateKeyName, cfg.PrivateKeyString, flagUsageMap[privateKeyName])
profilerEnabled := flag.Bool(profilerEnabledName, cfg.ProfilerEnabled, flagUsageMap[profilerEnabledName])
l1StartHash := flag.String(l1StartHashName, cfg.L1StartHash.Hex(), flagUsageMap[l1StartHashName])
sequencerID := flag.String(sequencerIDName, cfg.SequencerID.Hex(), flagUsageMap[sequencerIDName])
sequencerP2PAddress := flag.String(sequencerP2PAddrName, cfg.SequencerP2PAddress, flagUsageMap[sequencerP2PAddrName])
metricsEnabled := flag.Bool(metricsEnabledName, cfg.MetricsEnabled, flagUsageMap[metricsEnabledName])
metricsHTPPPort := flag.Uint(metricsHTTPPortName, cfg.MetricsHTTPPort, flagUsageMap[metricsHTTPPortName])
useInMemoryDB := flag.Bool(useInMemoryDBName, cfg.UseInMemoryDB, flagUsageMap[useInMemoryDBName])
Expand Down Expand Up @@ -129,7 +129,7 @@ func ParseConfig() (*config.HostInputConfig, error) {
cfg.ObscuroChainID = *obscuroChainID
cfg.ProfilerEnabled = *profilerEnabled
cfg.L1StartHash = gethcommon.HexToHash(*l1StartHash)
cfg.SequencerID = gethcommon.HexToAddress(*sequencerID)
cfg.SequencerP2PAddress = *sequencerP2PAddress
cfg.MetricsEnabled = *metricsEnabled
cfg.MetricsHTTPPort = *metricsHTPPPort
cfg.UseInMemoryDB = *useInMemoryDB
Expand Down Expand Up @@ -206,7 +206,7 @@ func fileBasedConfig(configPath string) (*config.HostInputConfig, error) {
ObscuroChainID: tomlConfig.ObscuroChainID,
ProfilerEnabled: tomlConfig.ProfilerEnabled,
L1StartHash: gethcommon.HexToHash(tomlConfig.L1StartHash),
SequencerID: gethcommon.HexToAddress(tomlConfig.SequencerID),
SequencerP2PAddress: tomlConfig.SequencerP2PAddress,
MetricsEnabled: tomlConfig.MetricsEnabled,
MetricsHTTPPort: tomlConfig.MetricsHTTPPort,
UseInMemoryDB: tomlConfig.UseInMemoryDB,
Expand Down
Loading
Loading