Skip to content

Commit

Permalink
chore: merge nitro changes (#586)
Browse files Browse the repository at this point in the history
      Co-authored-by: Goran Vladika <[email protected]>
Co-authored-by: Raul Jordan <[email protected]>
  • Loading branch information
gzeoneth authored Apr 5, 2024
1 parent f923fe0 commit c4e068b
Show file tree
Hide file tree
Showing 234 changed files with 39,559 additions and 7,470 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ jobs:
- name: Install packages
run: yarn

- name: Build
run: yarn build:all

- name: Run foundry tests
run: forge test

Expand Down Expand Up @@ -217,6 +220,11 @@ jobs:
with:
no-simple: false

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Setup node/yarn
uses: actions/setup-node@v3
with:
Expand All @@ -228,7 +236,7 @@ jobs:
run: yarn

- name: Compile contracts
run: yarn build
run: yarn build:all

- name: Copy .env
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ contracts/cache
contracts/out
contracts/formatter.sh
contracts/build
contracts/test/storage/*-old.dot
contracts/test/storage/*-old
contracts/test/signatures/*-old
contracts/coverage
contracts/lcov.info
contracts/forge-cache/

.DS_Store
.env
3 changes: 3 additions & 0 deletions assertions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ go_test(
"//challenge-manager",
"//challenge-manager/types",
"//containers/threadsafe",
"//solgen/go/bridgegen",
"//solgen/go/mocksgen",
"//solgen/go/rollupgen",
"//testing",
"//testing/mocks/state-provider",
"//testing/setup:setup_lib",
"//util",
"@com_github_ethereum_go_ethereum//accounts/abi",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//accounts/abi/bind/backends",
"@com_github_ethereum_go_ethereum//common",
"@com_github_stretchr_testify//require",
],
Expand Down
91 changes: 70 additions & 21 deletions assertions/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ package assertions_test
import (
"context"
"math/big"
"strings"
"testing"
"time"

"github.com/OffchainLabs/bold/assertions"
protocol "github.com/OffchainLabs/bold/chain-abstraction"
challengemanager "github.com/OffchainLabs/bold/challenge-manager"
"github.com/OffchainLabs/bold/challenge-manager/types"
"github.com/OffchainLabs/bold/solgen/go/bridgegen"
"github.com/OffchainLabs/bold/solgen/go/mocksgen"
"github.com/OffchainLabs/bold/solgen/go/rollupgen"
challenge_testing "github.com/OffchainLabs/bold/testing"
statemanager "github.com/OffchainLabs/bold/testing/mocks/state-provider"
"github.com/OffchainLabs/bold/testing/setup"
"github.com/OffchainLabs/bold/util"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

func TestSkipsProcessingAssertionFromEvilFork(t *testing.T) {
setup, err := setup.ChainsWithEdgeChallengeManager(
setup.WithMockBridge(),
setup.WithMockOneStepProver(),
setup.WithMockBridge(),
setup.WithChallengeTestingOpts(
challenge_testing.WithLayerZeroHeights(&protocol.LayerZeroHeights{
BlockChallengeHeight: 64,
Expand All @@ -40,12 +44,6 @@ func TestSkipsProcessingAssertionFromEvilFork(t *testing.T) {
bridgeBindings, err := mocksgen.NewBridgeStub(setup.Addrs.Bridge, setup.Backend)
require.NoError(t, err)

rollupAdminBindings, err := rollupgen.NewRollupAdminLogic(setup.Addrs.Rollup, setup.Backend)
require.NoError(t, err)
_, err = rollupAdminBindings.SetMinimumAssertionPeriod(setup.Accounts[0].TxOpts, big.NewInt(1))
require.NoError(t, err)
setup.Backend.Commit()

msgCount, err := bridgeBindings.SequencerMessageCount(util.GetSafeCallOpts(&bind.CallOpts{}))
require.NoError(t, err)
require.Equal(t, uint64(1), msgCount.Uint64())
Expand Down Expand Up @@ -133,9 +131,19 @@ func TestSkipsProcessingAssertionFromEvilFork(t *testing.T) {

// We have bob post an assertion at batch 2.
dataHash := [32]byte{1}
_, err = bridgeBindings.EnqueueSequencerMessage(setup.Accounts[0].TxOpts, dataHash, big.NewInt(1), big.NewInt(1), big.NewInt(2))
require.NoError(t, err)
setup.Backend.Commit()
enqueueSequencerMessageAsExecutor(
t,
setup.Accounts[0].TxOpts,
setup.Addrs.UpgradeExecutor,
setup.Backend,
setup.Addrs.Bridge,
seqMessage{
dataHash: dataHash,
afterDelayedMessagesRead: big.NewInt(1),
prevMessageCount: big.NewInt(1),
newMessageCount: big.NewInt(2),
},
)

genesisState, err := bobStateManager.ExecutionStateAfterPreviousState(ctx, 0, nil, 1<<26)
require.NoError(t, err)
Expand Down Expand Up @@ -165,7 +173,6 @@ func TestComplexAssertionForkScenario(t *testing.T) {
// and then we have another validator that disagrees with 4, so Charlie
// should open a 4' that branches off 3.
setup, err := setup.ChainsWithEdgeChallengeManager(
setup.WithMockBridge(),
setup.WithMockOneStepProver(),
setup.WithChallengeTestingOpts(
challenge_testing.WithLayerZeroHeights(&protocol.LayerZeroHeights{
Expand All @@ -180,12 +187,6 @@ func TestComplexAssertionForkScenario(t *testing.T) {
bridgeBindings, err := mocksgen.NewBridgeStub(setup.Addrs.Bridge, setup.Backend)
require.NoError(t, err)

rollupAdminBindings, err := rollupgen.NewRollupAdminLogic(setup.Addrs.Rollup, setup.Backend)
require.NoError(t, err)
_, err = rollupAdminBindings.SetMinimumAssertionPeriod(setup.Accounts[0].TxOpts, big.NewInt(1))
require.NoError(t, err)
setup.Backend.Commit()

msgCount, err := bridgeBindings.SequencerMessageCount(util.GetSafeCallOpts(&bind.CallOpts{}))
require.NoError(t, err)
require.Equal(t, uint64(1), msgCount.Uint64())
Expand Down Expand Up @@ -246,9 +247,19 @@ func TestComplexAssertionForkScenario(t *testing.T) {
count := int64(1)
for batch := 2; batch <= 4; batch++ {
dataHash := [32]byte{1}
_, err = bridgeBindings.EnqueueSequencerMessage(setup.Accounts[0].TxOpts, dataHash, big.NewInt(1), big.NewInt(count), big.NewInt(count+1))
require.NoError(t, err)
setup.Backend.Commit()
enqueueSequencerMessageAsExecutor(
t,
setup.Accounts[0].TxOpts,
setup.Addrs.UpgradeExecutor,
setup.Backend,
setup.Addrs.Bridge,
seqMessage{
dataHash: dataHash,
afterDelayedMessagesRead: big.NewInt(1),
prevMessageCount: big.NewInt(count),
newMessageCount: big.NewInt(count + 1),
},
)
count += 1

prevInfo, err2 := aliceChain.ReadAssertionCreationInfo(ctx, aliceAssertion.Id())
Expand Down Expand Up @@ -329,3 +340,41 @@ func TestComplexAssertionForkScenario(t *testing.T) {
// But blockhash should not match.
require.NotEqual(t, charliePostState.GlobalState.BlockHash, alicePostState.GlobalState.BlockHash)
}

type seqMessage struct {
dataHash common.Hash
afterDelayedMessagesRead *big.Int
prevMessageCount *big.Int
newMessageCount *big.Int
}

func enqueueSequencerMessageAsExecutor(
t *testing.T,
opts *bind.TransactOpts,
executor common.Address,
backend *backends.SimulatedBackend,
bridge common.Address,
msg seqMessage,
) {
execBindings, err := mocksgen.NewUpgradeExecutorMock(executor, backend)
require.NoError(t, err)
seqInboxABI, err := abi.JSON(strings.NewReader(bridgegen.AbsBridgeABI))
require.NoError(t, err)
data, err := seqInboxABI.Pack(
"setSequencerInbox",
executor,
)
require.NoError(t, err)
_, err = execBindings.ExecuteCall(opts, bridge, data)
require.NoError(t, err)
backend.Commit()

data, err = seqInboxABI.Pack(
"enqueueSequencerMessage",
msg.dataHash, msg.afterDelayedMessagesRead, msg.prevMessageCount, msg.newMessageCount,
)
require.NoError(t, err)
_, err = execBindings.ExecuteCall(opts, bridge, data)
require.NoError(t, err)
backend.Commit()
}
13 changes: 2 additions & 11 deletions assertions/poster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package assertions_test

import (
"context"
"math/big"
"testing"
"time"

Expand All @@ -14,7 +13,6 @@ import (
challengemanager "github.com/OffchainLabs/bold/challenge-manager"
"github.com/OffchainLabs/bold/challenge-manager/types"
"github.com/OffchainLabs/bold/solgen/go/mocksgen"
"github.com/OffchainLabs/bold/solgen/go/rollupgen"
challenge_testing "github.com/OffchainLabs/bold/testing"
statemanager "github.com/OffchainLabs/bold/testing/mocks/state-provider"
"github.com/OffchainLabs/bold/testing/setup"
Expand All @@ -24,8 +22,9 @@ import (
)

func TestPostAssertion(t *testing.T) {
ctx := context.Background()
setup, err := setup.ChainsWithEdgeChallengeManager(
setup.WithMockBridge(),
// setup.WithMockBridge(),
setup.WithMockOneStepProver(),
setup.WithChallengeTestingOpts(
challenge_testing.WithLayerZeroHeights(&protocol.LayerZeroHeights{
Expand All @@ -40,20 +39,12 @@ func TestPostAssertion(t *testing.T) {
bridgeBindings, err := mocksgen.NewBridgeStub(setup.Addrs.Bridge, setup.Backend)
require.NoError(t, err)

rollupAdminBindings, err := rollupgen.NewRollupAdminLogic(setup.Addrs.Rollup, setup.Backend)
require.NoError(t, err)
_, err = rollupAdminBindings.SetMinimumAssertionPeriod(setup.Accounts[0].TxOpts, big.NewInt(1))
require.NoError(t, err)
setup.Backend.Commit()

msgCount, err := bridgeBindings.SequencerMessageCount(util.GetSafeCallOpts(&bind.CallOpts{}))
require.NoError(t, err)
require.Equal(t, uint64(1), msgCount.Uint64())

aliceChain := setup.Chains[0]

ctx := context.Background()

stateManagerOpts := setup.StateManagerOpts
stateManagerOpts = append(
stateManagerOpts,
Expand Down
7 changes: 0 additions & 7 deletions assertions/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func Test_extractAssertionFromEvent(t *testing.T) {
})

setup, err := setup.ChainsWithEdgeChallengeManager(
setup.WithMockBridge(),
setup.WithMockOneStepProver(),
setup.WithChallengeTestingOpts(
challenge_testing.WithLayerZeroHeights(&protocol.LayerZeroHeights{
Expand All @@ -47,12 +46,6 @@ func Test_extractAssertionFromEvent(t *testing.T) {
bridgeBindings, err := mocksgen.NewBridgeStub(setup.Addrs.Bridge, setup.Backend)
require.NoError(t, err)

rollupAdminBindings, err := rollupgen.NewRollupAdminLogic(setup.Addrs.Rollup, setup.Backend)
require.NoError(t, err)
_, err = rollupAdminBindings.SetMinimumAssertionPeriod(setup.Accounts[0].TxOpts, big.NewInt(1))
require.NoError(t, err)
setup.Backend.Commit()

msgCount, err := bridgeBindings.SequencerMessageCount(util.GetSafeCallOpts(&bind.CallOpts{}))
require.NoError(t, err)
require.Equal(t, uint64(1), msgCount.Uint64())
Expand Down
2 changes: 2 additions & 0 deletions chain-abstraction/sol-implementation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ go_test(
"//chain-abstraction:protocol",
"//containers/option",
"//layer2-state-provider",
"//solgen/go/bridgegen",
"//solgen/go/mocksgen",
"//solgen/go/rollupgen",
"//state-commitments/history",
Expand All @@ -61,6 +62,7 @@ go_test(
"//testing/setup:setup_lib",
"//util",
"@com_github_ethereum_go_ethereum//:go-ethereum",
"@com_github_ethereum_go_ethereum//accounts/abi",
"@com_github_ethereum_go_ethereum//accounts/abi/bind",
"@com_github_ethereum_go_ethereum//accounts/abi/bind/backends",
"@com_github_ethereum_go_ethereum//common",
Expand Down
Loading

0 comments on commit c4e068b

Please sign in to comment.