Skip to content

Commit

Permalink
Addressed review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanIliev545 committed Jun 26, 2024
1 parent 2b622fd commit ba13bed
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 25 deletions.
28 changes: 14 additions & 14 deletions contracts/generated/ManagementContract/ManagementContract.go

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion contracts/src/management/ManagementContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
}
}

function addCrossChainMessagesRoot(bytes32 _lastBatchHash, bytes32 blockHash, uint256 blockNum, bytes[] memory crossChainHashes, bytes calldata signature) external {
function addCrossChainMessagesRoot(bytes32 _lastBatchHash, bytes32 blockHash, uint256 blockNum, bytes[] memory crossChainHashes, bytes calldata signature, uint256 rollupNumber, bytes32 forkID) external {
if (block.number > blockNum + 255) {
revert("Block binding too old");
}
Expand All @@ -111,6 +111,10 @@ contract ManagementContract is Initializable, OwnableUpgradeable {
revert(string(abi.encodePacked("Invalid block binding:", Strings.toString(block.number),":", Strings.toString(uint256(blockHash)), ":", Strings.toString(uint256(blockhash(blockNum))))));
}

if (rollups.toUniqueForkID[rollupNumber] != forkID) {
revert("Invalid forkID");
}

address enclaveID = ECDSA.recover(keccak256(abi.encode(_lastBatchHash, blockHash, blockNum, crossChainHashes)), signature);
require(attested[enclaveID], "enclaveID not attested"); //todo: only sequencer, rather than everyone who has attested.

Expand Down
2 changes: 1 addition & 1 deletion go/common/host/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ type L1Publisher interface {
PublishSecretResponse(secretResponse *common.ProducedSecretResponse) error

// PublishCrossChainBundle will create and publish a cross-chain bundle tx to the management contract
PublishCrossChainBundle(bundle *common.ExtCrossChainBundle) error
PublishCrossChainBundle(*common.ExtCrossChainBundle, *big.Int, gethcommon.Hash) error

FetchLatestSeqNo() (*big.Int, error)

Expand Down
4 changes: 2 additions & 2 deletions go/host/l1/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (p *Publisher) PublishRollup(producedRollup *common.ExtRollup) {
}
}

func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle) error {
func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle, rollupNum *big.Int, forkID gethcommon.Hash) error {
if p.mgmtContractLib.IsMock() {
return nil
}
Expand Down Expand Up @@ -313,7 +313,7 @@ func (p *Publisher) PublishCrossChainBundle(bundle *common.ExtCrossChainBundle)

transactor.Nonce = big.NewInt(0).SetUint64(nonce)

tx, err := managementCtr.AddCrossChainMessagesRoot(transactor, [32]byte(bundle.LastBatchHash.Bytes()), bundle.L1BlockHash, bundle.L1BlockNum, bundle.CrossChainRootHashes, bundle.Signature)
tx, err := managementCtr.AddCrossChainMessagesRoot(transactor, [32]byte(bundle.LastBatchHash.Bytes()), bundle.L1BlockHash, bundle.L1BlockNum, bundle.CrossChainRootHashes, bundle.Signature, rollupNum, forkID)
if err != nil {
if !errors.Is(err, errutil.ErrCrossChainBundleRepublished) {
p.logger.Error("Error with submitting cross chain bundle transaction.", log.ErrKey, err, log.BundleHashKey, bundle.LastBatchHash)
Expand Down
12 changes: 6 additions & 6 deletions go/host/l1/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type CrossChainStateMachine interface {
host.Service
}

// crossChainStateMachine - responsible for maintaining a view of the submitted cross chain bundles for the rollups on the L1.
// Whenever a reorg happens, the state machine will revert to the latest known common ancestor rollup.
// Bundles are only submitted after a rollup is pushed on the L1. The state machine will keep track of the latest rollup and the bundles that have been submitted.
type crossChainStateMachine struct {
latestRollup RollupInfo
rollupHistory map[RollupNumber]RollupInfo
Expand All @@ -41,7 +44,6 @@ type crossChainStateMachine struct {
}

type RollupInfo struct {
Hash gethcommon.Hash
ForkUID ForkUniqueID
Number RollupNumber
}
Expand All @@ -56,7 +58,6 @@ func NewCrossChainStateMachine(
) CrossChainStateMachine {
return &crossChainStateMachine{
latestRollup: RollupInfo{
Hash: gethcommon.Hash{},
ForkUID: gethcommon.Hash{},
Number: 0,
},
Expand Down Expand Up @@ -120,7 +121,7 @@ func (c *crossChainStateMachine) PublishNextBundle() error {
return err
}

err = c.publisher.PublishCrossChainBundle(bundle)
err = c.publisher.PublishCrossChainBundle(bundle, big.NewInt(0).SetUint64(data.Number), data.ForkUID)
if err != nil {
return err
}
Expand All @@ -141,7 +142,7 @@ func (c *crossChainStateMachine) Synchronize() error {
}

if errors.Is(err, errutil.ErrRollupForkMismatch) {
return c.RevertToLatestKnownCommonAncestorRollup()
return c.revertToLatestKnownCommonAncestorRollup()
}

c.logger.Error("Failed to get bundle range from management contract", "error", err)
Expand All @@ -150,15 +151,14 @@ func (c *crossChainStateMachine) Synchronize() error {

c.rollupHistory[c.latestRollup.Number] = c.latestRollup
c.latestRollup = RollupInfo{
Hash: gethcommon.Hash{},
ForkUID: *forkUID,
Number: c.latestRollup.Number + 1,
}

return nil
}

func (c *crossChainStateMachine) RevertToLatestKnownCommonAncestorRollup() error {
func (c *crossChainStateMachine) revertToLatestKnownCommonAncestorRollup() error {
managementContract, err := ManagementContract.NewManagementContract(*c.mgmtContractLib.GetContractAddr(), c.ethClient.EthClient())
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

func TestRunLocalNetwork(t *testing.T) {
networktest.TestOnlyRunsInIDE(t)
// networktest.TestOnlyRunsInIDE(t)
networktest.EnsureTestLogsSetUp("local-geth-network")
networkConnector, cleanUp, err := env.LocalDevNetwork(devnetwork.WithGateway()).Prepare()
if err != nil {
Expand Down

0 comments on commit ba13bed

Please sign in to comment.