From b134161cdbbe05ee6d4b8762a3329d9a9c487f23 Mon Sep 17 00:00:00 2001 From: the-laziest <161997049+the-laziest@users.noreply.github.com> Date: Mon, 6 May 2024 17:30:29 +0200 Subject: [PATCH 01/11] fix(eventindexer): nft balance changes should be wrapped in db transaction (#16943) Co-authored-by: jeff <113397187+cyberhorsey@users.noreply.github.com> --- .../indexer/index_nft_transfers.go | 35 +++++---- packages/eventindexer/nft_balance.go | 7 +- .../pkg/mock/nft_balance_repository.go | 16 ++--- packages/eventindexer/pkg/repo/nft_balance.go | 45 +++++++++--- .../eventindexer/pkg/repo/nft_balance_test.go | 71 +++++++------------ 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/packages/eventindexer/indexer/index_nft_transfers.go b/packages/eventindexer/indexer/index_nft_transfers.go index 385d7441e5..6f755ea865 100644 --- a/packages/eventindexer/indexer/index_nft_transfers.go +++ b/packages/eventindexer/indexer/index_nft_transfers.go @@ -116,35 +116,34 @@ func (i *Indexer) saveERC721Transfer(ctx context.Context, chainID *big.Int, vLog ) // increment To address's balance - - _, err := i.nftBalanceRepo.IncreaseBalance(ctx, eventindexer.UpdateNFTBalanceOpts{ + // decrement From address's balance + increaseOpts := eventindexer.UpdateNFTBalanceOpts{ ChainID: chainID.Int64(), Address: to, TokenID: tokenID, ContractAddress: vLog.Address.Hex(), ContractType: "ERC721", Amount: 1, // ERC721 is always 1 - }) - if err != nil { - return err } + decreaseOpts := eventindexer.UpdateNFTBalanceOpts{} - // decrement From address's balance // ignore zero address since that is usually the "mint" if from != ZeroAddress.Hex() { - _, err = i.nftBalanceRepo.SubtractBalance(ctx, eventindexer.UpdateNFTBalanceOpts{ + decreaseOpts = eventindexer.UpdateNFTBalanceOpts{ ChainID: chainID.Int64(), Address: from, TokenID: tokenID, ContractAddress: vLog.Address.Hex(), ContractType: "ERC721", Amount: 1, // ERC721 is always 1 - }) - if err != nil { - return err } } + _, _, err := i.nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(ctx, increaseOpts, decreaseOpts) + if err != nil { + return err + } + return nil } @@ -200,32 +199,32 @@ func (i *Indexer) saveERC1155Transfer(ctx context.Context, chainID *big.Int, vLo // increment To address's balance for _, transfer := range transfers { - _, err = i.nftBalanceRepo.IncreaseBalance(ctx, eventindexer.UpdateNFTBalanceOpts{ + increaseOpts := eventindexer.UpdateNFTBalanceOpts{ ChainID: chainID.Int64(), Address: to, TokenID: transfer.ID.Int64(), ContractAddress: vLog.Address.Hex(), ContractType: "ERC1155", Amount: transfer.Amount.Int64(), - }) - if err != nil { - return err } + decreaseOpts := eventindexer.UpdateNFTBalanceOpts{} if from != ZeroAddress.Hex() { // decrement From address's balance - _, err = i.nftBalanceRepo.SubtractBalance(ctx, eventindexer.UpdateNFTBalanceOpts{ + decreaseOpts = eventindexer.UpdateNFTBalanceOpts{ ChainID: chainID.Int64(), Address: from, TokenID: transfer.ID.Int64(), ContractAddress: vLog.Address.Hex(), ContractType: "ERC1155", Amount: transfer.Amount.Int64(), - }) - if err != nil { - return err } } + + _, _, err = i.nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(ctx, increaseOpts, decreaseOpts) + if err != nil { + return err + } } return nil diff --git a/packages/eventindexer/nft_balance.go b/packages/eventindexer/nft_balance.go index 9b1651a49b..1497b32d6e 100644 --- a/packages/eventindexer/nft_balance.go +++ b/packages/eventindexer/nft_balance.go @@ -30,8 +30,11 @@ type UpdateNFTBalanceOpts struct { // NFTBalanceRepository is used to interact with nft balances in the store type NFTBalanceRepository interface { - SubtractBalance(ctx context.Context, opts UpdateNFTBalanceOpts) (*NFTBalance, error) - IncreaseBalance(ctx context.Context, opts UpdateNFTBalanceOpts) (*NFTBalance, error) + IncreaseAndDecreaseBalancesInTx( + ctx context.Context, + increaseOpts UpdateNFTBalanceOpts, + decreaseOpts UpdateNFTBalanceOpts, + ) (increasedBalance *NFTBalance, decreasedBalance *NFTBalance, err error) FindByAddress(ctx context.Context, req *http.Request, address string, diff --git a/packages/eventindexer/pkg/mock/nft_balance_repository.go b/packages/eventindexer/pkg/mock/nft_balance_repository.go index 4b55cae4b7..a043371a5d 100644 --- a/packages/eventindexer/pkg/mock/nft_balance_repository.go +++ b/packages/eventindexer/pkg/mock/nft_balance_repository.go @@ -16,18 +16,12 @@ func NewNFTBalanceRepository() *NFTBalanceRepository { return &NFTBalanceRepository{} } -func (r *NFTBalanceRepository) SubtractBalance( +func (r *NFTBalanceRepository) IncreaseAndDecreaseBalancesInTx( ctx context.Context, - opts eventindexer.UpdateNFTBalanceOpts, -) (*eventindexer.NFTBalance, error) { - return nil, nil -} - -func (r *NFTBalanceRepository) IncreaseBalance( - ctx context.Context, - opts eventindexer.UpdateNFTBalanceOpts, -) (*eventindexer.NFTBalance, error) { - return nil, nil + increaseOpts eventindexer.UpdateNFTBalanceOpts, + decreaseOpts eventindexer.UpdateNFTBalanceOpts, +) (increasedBalance *eventindexer.NFTBalance, decreasedBalance *eventindexer.NFTBalance, err error) { + return nil, nil, nil } func (r *NFTBalanceRepository) FindByAddress(ctx context.Context, diff --git a/packages/eventindexer/pkg/repo/nft_balance.go b/packages/eventindexer/pkg/repo/nft_balance.go index c3ec5e381d..ccd6df691b 100644 --- a/packages/eventindexer/pkg/repo/nft_balance.go +++ b/packages/eventindexer/pkg/repo/nft_balance.go @@ -24,8 +24,9 @@ func NewNFTBalanceRepository(db eventindexer.DB) (*NFTBalanceRepository, error) }, nil } -func (r *NFTBalanceRepository) IncreaseBalance( +func (r *NFTBalanceRepository) increaseBalanceInDB( ctx context.Context, + db *gorm.DB, opts eventindexer.UpdateNFTBalanceOpts, ) (*eventindexer.NFTBalance, error) { b := &eventindexer.NFTBalance{ @@ -34,11 +35,9 @@ func (r *NFTBalanceRepository) IncreaseBalance( Address: opts.Address, ContractType: opts.ContractType, ChainID: opts.ChainID, - Amount: 0, } - err := r.db. - GormDB(). + err := db. Where("contract_address = ?", opts.ContractAddress). Where("token_id = ?", opts.TokenID). Where("address = ?", opts.Address). @@ -55,15 +54,16 @@ func (r *NFTBalanceRepository) IncreaseBalance( b.Amount += opts.Amount // update the row to reflect new balance - if err := r.db.GormDB().Save(b).Error; err != nil { + if err := db.Save(b).Error; err != nil { return nil, errors.Wrap(err, "r.db.Save") } return b, nil } -func (r *NFTBalanceRepository) SubtractBalance( +func (r *NFTBalanceRepository) decreaseBalanceInDB( ctx context.Context, + db *gorm.DB, opts eventindexer.UpdateNFTBalanceOpts, ) (*eventindexer.NFTBalance, error) { b := &eventindexer.NFTBalance{ @@ -74,8 +74,7 @@ func (r *NFTBalanceRepository) SubtractBalance( ChainID: opts.ChainID, } - err := r.db. - GormDB(). + err := db. Where("contract_address = ?", opts.ContractAddress). Where("token_id = ?", opts.TokenID). Where("address = ?", opts.Address). @@ -86,7 +85,7 @@ func (r *NFTBalanceRepository) SubtractBalance( if err != gorm.ErrRecordNotFound { return nil, errors.Wrap(err, "r.db.gormDB.First") } else { - // cant subtract a balance if user never had this balance, indexing issue + // cant decrease a balance if user never had this balance, indexing issue return nil, nil } } @@ -95,12 +94,12 @@ func (r *NFTBalanceRepository) SubtractBalance( // we can just delete the row, this user has no more of this NFT if b.Amount == 0 { - if err := r.db.GormDB().Delete(b).Error; err != nil { + if err := db.Delete(b).Error; err != nil { return nil, errors.Wrap(err, "r.db.Delete") } } else { // update the row instead to reflect new balance - if err := r.db.GormDB().Save(b).Error; err != nil { + if err := db.Save(b).Error; err != nil { return nil, errors.Wrap(err, "r.db.Save") } } @@ -108,6 +107,30 @@ func (r *NFTBalanceRepository) SubtractBalance( return b, nil } +func (r *NFTBalanceRepository) IncreaseAndDecreaseBalancesInTx( + ctx context.Context, + increaseOpts eventindexer.UpdateNFTBalanceOpts, + decreaseOpts eventindexer.UpdateNFTBalanceOpts, +) (increasedBalance *eventindexer.NFTBalance, decreasedBalance *eventindexer.NFTBalance, err error) { + err = r.db.GormDB().Transaction(func(tx *gorm.DB) (err error) { + increasedBalance, err = r.increaseBalanceInDB(ctx, tx, increaseOpts) + if err != nil { + return err + } + + if decreaseOpts.Amount != 0 { + decreasedBalance, err = r.decreaseBalanceInDB(ctx, tx, decreaseOpts) + } + + return err + }) + if err != nil { + return nil, nil, errors.Wrap(err, "r.db.Transaction") + } + + return increasedBalance, decreasedBalance, nil +} + func (r *NFTBalanceRepository) FindByAddress(ctx context.Context, req *http.Request, address string, diff --git a/packages/eventindexer/pkg/repo/nft_balance_test.go b/packages/eventindexer/pkg/repo/nft_balance_test.go index 15416b29b0..86d04be860 100644 --- a/packages/eventindexer/pkg/repo/nft_balance_test.go +++ b/packages/eventindexer/pkg/repo/nft_balance_test.go @@ -39,7 +39,7 @@ func Test_NewNFTBalanceRepo(t *testing.T) { } } -func TestIntegration_NFTBalance_Increase(t *testing.T) { +func TestIntegration_NFTBalance_Increase_And_Decrease(t *testing.T) { db, close, err := testMysql(t) assert.Equal(t, nil, err) @@ -48,43 +48,7 @@ func TestIntegration_NFTBalance_Increase(t *testing.T) { nftBalanceRepo, err := NewNFTBalanceRepository(db) assert.Equal(t, nil, err) - tests := []struct { - name string - opts eventindexer.UpdateNFTBalanceOpts - wantErr error - }{ - { - "success", - eventindexer.UpdateNFTBalanceOpts{ - ChainID: 1, - Address: "0x123", - TokenID: 1, - ContractAddress: "0x123", - ContractType: "ERC721", - Amount: 1, - }, - nil, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - _, err := nftBalanceRepo.IncreaseBalance(context.Background(), tt.opts) - assert.Equal(t, tt.wantErr, err) - }) - } -} - -func TestIntegration_NFTBalance_Decrease(t *testing.T) { - db, close, err := testMysql(t) - assert.Equal(t, nil, err) - - defer close() - - nftBalanceRepo, err := NewNFTBalanceRepository(db) - assert.Equal(t, nil, err) - - bal1, err := nftBalanceRepo.IncreaseBalance(context.Background(), + bal1, _, err := nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(context.Background(), eventindexer.UpdateNFTBalanceOpts{ ChainID: 1, Address: "0x123", @@ -92,11 +56,11 @@ func TestIntegration_NFTBalance_Decrease(t *testing.T) { ContractAddress: "0x123", ContractType: "ERC721", Amount: 1, - }) + }, eventindexer.UpdateNFTBalanceOpts{}) assert.Equal(t, nil, err) assert.NotNil(t, bal1) - bal2, err := nftBalanceRepo.IncreaseBalance(context.Background(), + bal2, _, err := nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(context.Background(), eventindexer.UpdateNFTBalanceOpts{ ChainID: 1, Address: "0x123", @@ -104,17 +68,26 @@ func TestIntegration_NFTBalance_Decrease(t *testing.T) { ContractAddress: "0x123456", ContractType: "ERC721", Amount: 2, - }) + }, eventindexer.UpdateNFTBalanceOpts{}) assert.Equal(t, nil, err) assert.NotNil(t, bal2) tests := []struct { - name string - opts eventindexer.UpdateNFTBalanceOpts - wantErr error + name string + increaseOpts eventindexer.UpdateNFTBalanceOpts + decreaseOpts eventindexer.UpdateNFTBalanceOpts + wantErr error }{ { "success", + eventindexer.UpdateNFTBalanceOpts{ + ChainID: 1, + Address: "0x123", + TokenID: 1, + ContractAddress: "0x123456789", + ContractType: "ERC721", + Amount: 1, + }, eventindexer.UpdateNFTBalanceOpts{ ChainID: 1, Address: "0x123", @@ -127,6 +100,14 @@ func TestIntegration_NFTBalance_Decrease(t *testing.T) { }, { "one left", + eventindexer.UpdateNFTBalanceOpts{ + ChainID: 1, + Address: "0x123", + TokenID: 1, + ContractAddress: "0x123456789", + ContractType: "ERC721", + Amount: 1, + }, eventindexer.UpdateNFTBalanceOpts{ ChainID: 1, Address: "0x123", @@ -141,7 +122,7 @@ func TestIntegration_NFTBalance_Decrease(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - _, err := nftBalanceRepo.SubtractBalance(context.Background(), tt.opts) + _, _, err := nftBalanceRepo.IncreaseAndDecreaseBalancesInTx(context.Background(), tt.increaseOpts, tt.decreaseOpts) assert.Equal(t, tt.wantErr, err) }) } From 5658796c809d2b4372eecab5a15a7cf03b378ddf Mon Sep 17 00:00:00 2001 From: brachsterX Date: Mon, 6 May 2024 19:21:33 +0200 Subject: [PATCH 02/11] chore(protocol): fix links in docs (#16977) Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com> --- packages/protocol/docs/how_taiko_proves_blocks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/protocol/docs/how_taiko_proves_blocks.md b/packages/protocol/docs/how_taiko_proves_blocks.md index 0c5d1c3e3e..1d1dd7dcf0 100644 --- a/packages/protocol/docs/how_taiko_proves_blocks.md +++ b/packages/protocol/docs/how_taiko_proves_blocks.md @@ -109,7 +109,7 @@ struct BlockMetadata { The following [**block level variables**](https://docs.soliditylang.org/en/latest/units-and-global-variables.html) are accessible to the EVM, but their values are not part of the MPT so we need a different way to verify their correctness. - `blockhash(uint blockNumber) returns (bytes32)`: hash of the given block when `blocknumber` is one of the 256 most recent blocks; otherwise returns zero -- `block.basefee` (`uint`): current block's base fee ([EIP-3198](https://eips.ethereum.org/EIPS/eip-3198) and [modified EIP-1559](./L2EIP1559.md)) +- `block.basefee` (`uint`): current block's base fee ([EIP-3198](https://eips.ethereum.org/EIPS/eip-3198) and [modified EIP-1559](eip1559_on_l2.md)) - `block.chainid` (`uint`): current chain id - `block.coinbase` (`address payable`): current block miner's address - `block.prevrandao` (`uint`): alias for `block.prevrandao` ([EIP-4399](https://eips.ethereum.org/EIPS/eip-4399)) From 2677708d395fb3043250a78854e0688284fb5b1c Mon Sep 17 00:00:00 2001 From: Edvin Ukko <168254967+edvenukko@users.noreply.github.com> Date: Tue, 7 May 2024 08:52:46 +0800 Subject: [PATCH 03/11] fix(eventindexer): fix Dockerfile problems (#16996) Co-authored-by: jeff <113397187+cyberhorsey@users.noreply.github.com> Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> --- Dockerfile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 67e3abdafe..a1d52db69d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ +ARG PACKAGE=eventindexer + FROM golang:1.21.0 as builder -ARG PACKAGE=eventindexer +ARG PACKAGE RUN apt install git curl @@ -12,16 +14,17 @@ COPY . . RUN go mod download -WORKDIR /taiko-mono/packages/$PACKAGE +WORKDIR /taiko-mono/packages/${PACKAGE} -RUN CGO_ENABLED=0 GOOS=linux go build -o /taiko-mono/packages/$PACKAGE/bin/${PACKAGE} /taiko-mono/packages/$PACKAGE/cmd/main.go +RUN CGO_ENABLED=0 GOOS=linux go build -o /taiko-mono/packages/${PACKAGE}/bin/${PACKAGE} /taiko-mono/packages/${PACKAGE}/cmd/main.go FROM alpine:latest ARG PACKAGE +ENV PACKAGE=${PACKAGE} RUN apk add --no-cache ca-certificates -COPY --from=builder /taiko-mono/packages/$PACKAGE/bin/$PACKAGE /usr/local/bin/ +COPY --from=builder /taiko-mono/packages/${PACKAGE}/bin/${PACKAGE} /usr/local/bin/ -ENTRYPOINT ["$PACKAGE"] \ No newline at end of file +ENTRYPOINT /usr/local/bin/${PACKAGE} \ No newline at end of file From 84080d4f2318b9742805deb9d680fa73760a44af Mon Sep 17 00:00:00 2001 From: polebug Date: Tue, 7 May 2024 10:05:55 +0800 Subject: [PATCH 04/11] fix(eventindexer): fix match logic for transferBatchSignatureHash (#17015) --- packages/eventindexer/indexer/filter.go | 2 +- packages/eventindexer/indexer/index_nft_transfers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eventindexer/indexer/filter.go b/packages/eventindexer/indexer/filter.go index 09a0e99ad6..d7849d3efe 100644 --- a/packages/eventindexer/indexer/filter.go +++ b/packages/eventindexer/indexer/filter.go @@ -36,7 +36,7 @@ func filterFunc( err = i.saveTransitionProvedEvents(ctx, chainID, transitionProvedEvents) if err != nil { - return errors.Wrap(err, "i.saveBlockProvenEvents") + return errors.Wrap(err, "i.saveTransitionProvedEvents") } return nil diff --git a/packages/eventindexer/indexer/index_nft_transfers.go b/packages/eventindexer/indexer/index_nft_transfers.go index 6f755ea865..d27a35fdce 100644 --- a/packages/eventindexer/indexer/index_nft_transfers.go +++ b/packages/eventindexer/indexer/index_nft_transfers.go @@ -177,7 +177,7 @@ func (i *Indexer) saveERC1155Transfer(ctx context.Context, chainID *big.Int, vLo } transfers = append(transfers, t) - } else if vLog.Topics[0].Hex() != transferBatchSignatureHash.Hex() { + } else if vLog.Topics[0].Hex() == transferBatchSignatureHash.Hex() { var t []transfer err = erc1155ABI.UnpackIntoInterface(&t, "TransferBatch", []byte(vLog.Data)) From 40e2b0cf547a2a053ca41ba0eea0cefa91c89454 Mon Sep 17 00:00:00 2001 From: bytenoob Date: Tue, 7 May 2024 10:36:51 +0800 Subject: [PATCH 05/11] chore(relayer): remove redundant code and add log for errTxReverted (#17012) Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com> --- packages/relayer/processor/process_message.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/relayer/processor/process_message.go b/packages/relayer/processor/process_message.go index bc609f8a01..0ce7b430b6 100644 --- a/packages/relayer/processor/process_message.go +++ b/packages/relayer/processor/process_message.go @@ -98,15 +98,11 @@ func (p *Processor) processMessage( return false, msgBody.TimesRetried, err } - receipt, err := p.sendProcessMessageCall(ctx, msgBody.Event, encodedSignalProof) + _, err = p.sendProcessMessageCall(ctx, msgBody.Event, encodedSignalProof) if err != nil { return false, msgBody.TimesRetried, err } - if receipt.Status != types.ReceiptStatusSuccessful { - return false, msgBody.TimesRetried, err - } - messageStatus, err := p.destBridge.MessageStatus(&bind.CallOpts{ Context: ctx, }, msgBody.Event.MsgHash) @@ -412,6 +408,9 @@ func (p *Processor) sendProcessMessageCall( if receipt.Status != types.ReceiptStatusSuccessful { relayer.MessageSentEventsProcessedReverted.Inc() + slog.Warn("Transaction reverted", "txHash", hex.EncodeToString(receipt.TxHash.Bytes()), + "srcTxHash", event.Raw.TxHash.Hex(), + "status", receipt.Status) return nil, errTxReverted } From fcbc3463e623b81eb5ed9f73c5098e5fbea874ca Mon Sep 17 00:00:00 2001 From: ukurenov <154307006+ukurenov@users.noreply.github.com> Date: Tue, 7 May 2024 05:37:52 +0300 Subject: [PATCH 06/11] fix(bridge-ui): dropdown css and color css fix (#17000) Co-authored-by: Korbinian --- .../ImportStep/TokenInput/TokenInput.svelte | 6 +++--- .../ChainSelectors/SelectorDialogs/ChainsDialog.svelte | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ImportStep/TokenInput/TokenInput.svelte b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ImportStep/TokenInput/TokenInput.svelte index 8f81bbb7da..f70cea6767 100644 --- a/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ImportStep/TokenInput/TokenInput.svelte +++ b/packages/bridge-ui/src/components/Bridge/FungibleBridgeComponents/ImportStep/TokenInput/TokenInput.svelte @@ -231,7 +231,7 @@ - +
@@ -242,9 +242,9 @@ >{$t('recipient.label')}
{:else if showInsufficientBalanceAlert} - + {:else if showInvalidTokenAlert} - + {:else} {/if} diff --git a/packages/bridge-ui/src/components/ChainSelectors/SelectorDialogs/ChainsDialog.svelte b/packages/bridge-ui/src/components/ChainSelectors/SelectorDialogs/ChainsDialog.svelte index 2e1843a53d..6317de54fa 100644 --- a/packages/bridge-ui/src/components/ChainSelectors/SelectorDialogs/ChainsDialog.svelte +++ b/packages/bridge-ui/src/components/ChainSelectors/SelectorDialogs/ChainsDialog.svelte @@ -62,10 +62,10 @@
  • -
    - - - -
    + + +
    From 23bfeb66f1a0d4c11b5784a8467087fea315157a Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Tue, 7 May 2024 14:19:58 +0800 Subject: [PATCH 08/11] refactor(protocol): improve block liveness bond handling (#17010) --- .../protocol/contracts/L1/libs/LibProving.sol | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/packages/protocol/contracts/L1/libs/LibProving.sol b/packages/protocol/contracts/L1/libs/LibProving.sol index 8ec5457308..1dd60fc06d 100644 --- a/packages/protocol/contracts/L1/libs/LibProving.sol +++ b/packages/protocol/contracts/L1/libs/LibProving.sol @@ -23,7 +23,6 @@ library LibProving { ITierProvider.Tier tier; bytes32 metaHash; address assignedProver; - uint96 livenessBond; uint64 slot; uint64 blockId; uint32 tid; @@ -201,26 +200,8 @@ library LibProving { } local.isTopTier = local.tier.contestBond == 0; - IERC20 tko = IERC20(_resolver.resolve(LibStrings.B_TAIKO_TOKEN, false)); - - local.livenessBond = blk.livenessBond; - if (local.isTopTier) { - if (local.livenessBond != 0) { - if ( - local.inProvingWindow - || ( - _proof.data.length == 32 - && bytes32(_proof.data) == LibStrings.H_RETURN_LIVENESS_BOND - ) - ) { - tko.safeTransfer(local.assignedProver, local.livenessBond); - } - blk.livenessBond = 0; - local.livenessBond = 0; - } - } - local.sameTransition = _tran.blockHash == ts.blockHash && _tran.stateRoot == ts.stateRoot; + IERC20 tko = IERC20(_resolver.resolve(LibStrings.B_TAIKO_TOKEN, false)); if (_proof.tier > ts.tier) { // Handles the case when an incoming tier is higher than the current transition's tier. @@ -403,6 +384,8 @@ library LibProving { uint256 reward; // reward to the new (current) prover if (_ts.contester != address(0)) { + // assert(_blk.livenessBond == 0); + if (_local.sameTransition) { // The contested transition is proven to be valid, contester loses the game reward = _rewardAfterFriction(_ts.contestBond); @@ -424,14 +407,19 @@ library LibProving { // - 2) the transition is contested. reward = _rewardAfterFriction(_ts.validityBond); - if (_local.livenessBond != 0) { - if (_local.assignedProver == msg.sender && _local.inProvingWindow) { - unchecked { - reward += _local.livenessBond; + uint256 livenessBond = _blk.livenessBond; + if (livenessBond != 0) { + // After the first proof, the block's liveness bond will always be reset to 0. + // This means liveness bond will be handled only once for any given block. + _blk.livenessBond = 0; + + if (_returnLivenessBond(_local, _proof.data)) { + if (_blk.assignedProver == msg.sender) { + reward += livenessBond; + } else { + _tko.safeTransfer(_blk.assignedProver, livenessBond); } } - _blk.livenessBond = 0; - _local.livenessBond = 0; } } @@ -459,4 +447,18 @@ library LibProving { function _rewardAfterFriction(uint256 _amount) private pure returns (uint256) { return _amount == 0 ? 0 : (_amount * 7) >> 3; } + + /// @dev Returns if the liveness bond shall be returned. + function _returnLivenessBond( + Local memory _local, + bytes memory _proofData + ) + private + pure + returns (bool) + { + return _local.inProvingWindow && _local.tid == 1 + || _local.isTopTier && _proofData.length == 32 + && bytes32(_proofData) == LibStrings.H_RETURN_LIVENESS_BOND; + } } From c2a4a330c814b5469488f6bf513f45ad276d3e6f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:21:12 +0800 Subject: [PATCH 09/11] chore(deps): bump github.com/urfave/cli/v2 from 2.27.1 to 2.27.2 (#16990) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 7ba5c1d7a4..fc7a8ac66b 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( github.com/stretchr/testify v1.9.0 github.com/swaggo/swag v1.16.3 github.com/testcontainers/testcontainers-go v0.30.0 - github.com/urfave/cli/v2 v2.27.1 + github.com/urfave/cli/v2 v2.27.2 golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3 golang.org/x/sync v0.7.0 gopkg.in/go-playground/assert.v1 v1.2.1 @@ -76,7 +76,7 @@ require ( github.com/containerd/containerd v1.7.12 // indirect github.com/containerd/log v0.1.0 // indirect github.com/cpuguy83/dockercfg v0.3.1 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 // indirect github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect @@ -186,7 +186,7 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect - github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect github.com/yosssi/ace v0.0.5 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect diff --git a/go.sum b/go.sum index 3059ac3505..5779c6068a 100644 --- a/go.sum +++ b/go.sum @@ -137,8 +137,8 @@ github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= -github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233 h1:d28BXYi+wUpz1KBmiF9bWrjEMacUEREV6MBi2ODnrfQ= github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs= github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= @@ -643,8 +643,8 @@ github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898 h1: github.com/tursodatabase/libsql-client-go v0.0.0-20240220085343-4ae0eb9d0898/go.mod h1:9bKuHS7eZh/0mJndbUOrCx8Ej3PlsRDszj4L7oVYMPQ= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= -github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= -github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= +github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI= +github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.22.0/go.mod h1:0mw2RjXGOzxf4NL2jni3gUQ7LfjjUSiG5sskOUUSEpU= @@ -671,8 +671,8 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= -github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw= +github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= github.com/ydb-platform/ydb-go-genproto v0.0.0-20240126124512-dbb0e1720dbf h1:ckwNHVo4bv2tqNkgx3W3HANh3ta1j6TR5qw08J1A7Tw= From b978e11ae6f0c0e7c4c69077a4d953d53943d4ed Mon Sep 17 00:00:00 2001 From: D <51912515+adaki2004@users.noreply.github.com> Date: Tue, 7 May 2024 09:22:40 +0200 Subject: [PATCH 10/11] chore(protocol): add script to deploy and change TKO in ERC20Vault (#16974) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Keszey Dániel --- .../DeployAndChangeTaikoTokenOnL2.s.sol | 59 +++++++++++++++++++ .../protocol/script/SetupUSDCBridging.s.sol | 55 ----------------- 2 files changed, 59 insertions(+), 55 deletions(-) create mode 100644 packages/protocol/script/DeployAndChangeTaikoTokenOnL2.s.sol delete mode 100644 packages/protocol/script/SetupUSDCBridging.s.sol diff --git a/packages/protocol/script/DeployAndChangeTaikoTokenOnL2.s.sol b/packages/protocol/script/DeployAndChangeTaikoTokenOnL2.s.sol new file mode 100644 index 0000000000..1f41b830a3 --- /dev/null +++ b/packages/protocol/script/DeployAndChangeTaikoTokenOnL2.s.sol @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.24; + +import "../test/DeployCapability.sol"; +import "../contracts/tko/BridgedTaikoToken.sol"; +import "../contracts/tokenvault/ERC20Vault.sol"; + +contract DeployAndChangeTaikoTokenOnL2 is DeployCapability { + // If the private key to deploy proxy shall be different to the private key to changing the + // vault's bridge address(changeBridgedToken) then we need 2 private keys. + + address public vaultOwner = vm.envAddress("VAULT_OWNER"); + uint256 public vaultOwnerPrivateKey = vm.envUint("VAULT_OWNER_PRIVATE_KEY"); + address public l2Erc20Vault = vm.envAddress("ERC20_VAULT_ON_L2"); + + modifier broadcast() { + require(vaultOwnerPrivateKey != 0, "invalid private key"); + vm.startBroadcast(); + _; + vm.stopBroadcast(); + } + + function run() external broadcast { + // Change BridgedToken + ERC20Vault vault = ERC20Vault(l2Erc20Vault); + + // Deploy the TaikoToken contract on L2 + address deployedTkoProxy = deployProxy({ + name: "taiko_token", + impl: address(new BridgedTaikoToken()), + data: abi.encodeCall(BridgedTaikoToken.init, (vaultOwner, vault.addressManager())) + }); + + (address canonicalTkoAddress, uint256 chainId) = + BridgedTaikoToken(deployedTkoProxy).canonical(); + + address currBridgedtoken = vault.canonicalToBridged(chainId, canonicalTkoAddress); + assert(currBridgedtoken == address(0)); + + vault.changeBridgedToken( + ERC20Vault.CanonicalERC20({ + chainId: uint64(chainId), + addr: canonicalTkoAddress, + decimals: 18, + symbol: "TKO", + name: "Taiko Token" + }), + deployedTkoProxy + ); + if (vault.paused()) { + vault.unpause(); + } + + address newBridgedToken = vault.canonicalToBridged(chainId, canonicalTkoAddress); + console2.log("new btoken for tko:", newBridgedToken); + + require(deployedTkoProxy == newBridgedToken, "unexpected result"); + } +} diff --git a/packages/protocol/script/SetupUSDCBridging.s.sol b/packages/protocol/script/SetupUSDCBridging.s.sol deleted file mode 100644 index d04b79d866..0000000000 --- a/packages/protocol/script/SetupUSDCBridging.s.sol +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.24; - -import "../test/DeployCapability.sol"; -import "../contracts/tokenvault/ERC20Vault.sol"; - -/// @dev This script shall be run on Taiko chain to hook up a native USDC deployment and the USDC -/// deployed on layer 1. -/// -/// To deploy a native USDC contract on L2, run: -/// https://github.com/taikoxyz/USDC/blob/main/script/DeployUSDC.s.sol -contract SetupUSDCBridging is DeployCapability { - address public constant USDC_ON_ETHEREUM = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48; - - uint256 public privateKey = vm.envUint("PRIVATE_KEY"); - address public erc20VaultOnL2 = vm.envAddress("ERC20_VAULT_ON_L2"); - - // These are FiatTokenProxy addresses of the USDC coin. - address public usdcOnL1 = vm.envAddress("USDC_ADDRESS_ON_L1"); - address public usdcOnL2 = vm.envAddress("USDC_ADDRESS_ON_L2"); - - function run() external { - require(erc20VaultOnL2 != address(0) && usdcOnL2 != address(0), "invalid params"); - - if (usdcOnL1 == address(0)) { - usdcOnL1 = USDC_ON_ETHEREUM; - } - - ERC20Vault vault = ERC20Vault(erc20VaultOnL2); - - address currBridgedtoken = vault.canonicalToBridged(1, usdcOnL1); - console2.log("current btoken for usdc:", currBridgedtoken); - - vm.startBroadcast(privateKey); - vault.changeBridgedToken( - ERC20Vault.CanonicalERC20({ - chainId: 1, - addr: usdcOnL1, - decimals: 6, - symbol: "USDC", - name: "USD Coin" - }), - usdcOnL2 - ); - if (vault.paused()) { - vault.unpause(); - } - vm.stopBroadcast(); - - address newBridgedToken = vault.canonicalToBridged(1, usdcOnL1); - console2.log("new btoken for usdc:", newBridgedToken); - - require(usdcOnL2 == newBridgedToken, "unexpected result"); - } -} From 88a13b65478d96b7538d43561ebd0641514d9511 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 7 May 2024 17:37:28 +0800 Subject: [PATCH 11/11] feat(protocol): remove more timelock related code (#17018) --- .../script/SetRemoteBridgeSuites.s.sol | 40 +++---------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/packages/protocol/script/SetRemoteBridgeSuites.s.sol b/packages/protocol/script/SetRemoteBridgeSuites.s.sol index a851ff7715..2b757fb61f 100644 --- a/packages/protocol/script/SetRemoteBridgeSuites.s.sol +++ b/packages/protocol/script/SetRemoteBridgeSuites.s.sol @@ -6,7 +6,6 @@ import "../test/DeployCapability.sol"; contract SetRemoteBridgeSuites is DeployCapability { uint256 public privateKey = vm.envUint("PRIVATE_KEY"); uint256 public securityCouncilPrivateKey = vm.envUint("SECURITY_COUNCIL_PRIVATE_KEY"); - address public timelockAddress = vm.envAddress("TIMELOCK_ADDRESS"); address public addressManagerAddress = vm.envAddress("ADDRESS_MANAGER_ADDRESS"); uint256[] public remoteChainIDs = vm.envUint("REMOTE_CHAIN_IDS", ","); address[] public remoteSignalServices = vm.envAddress("REMOTE_SIGNAL_SERVICES", ","); @@ -40,42 +39,13 @@ contract SetRemoteBridgeSuites is DeployCapability { for (uint256 i; i < remoteChainIDs.length; ++i) { uint64 chainid = uint64(remoteChainIDs[i]); - - if (securityCouncilPrivateKey == 0) { - register(addressManagerAddress, "signal_service", remoteSignalServices[i], chainid); - register(addressManagerAddress, "bridge", remoteBridges[i], chainid); - register(addressManagerAddress, "erc20_vault", remoteERC20Vaults[i], chainid); - register(addressManagerAddress, "erc721_vault", remoteERC721Vaults[i], chainid); - register(addressManagerAddress, "erc1155_vault", remoteERC1155Vaults[i], chainid); - continue; - } - - registerByTimelock( - addressManagerAddress, "signal_service", remoteSignalServices[i], chainid - ); - registerByTimelock(addressManagerAddress, "bridge", remoteBridges[i], chainid); - registerByTimelock(addressManagerAddress, "erc20_vault", remoteERC20Vaults[i], chainid); - registerByTimelock( - addressManagerAddress, "erc721_vault", remoteERC721Vaults[i], chainid - ); - registerByTimelock( - addressManagerAddress, "erc1155_vault", remoteERC1155Vaults[i], chainid - ); + register(addressManagerAddress, "signal_service", remoteSignalServices[i], chainid); + register(addressManagerAddress, "bridge", remoteBridges[i], chainid); + register(addressManagerAddress, "erc20_vault", remoteERC20Vaults[i], chainid); + register(addressManagerAddress, "erc721_vault", remoteERC721Vaults[i], chainid); + register(addressManagerAddress, "erc1155_vault", remoteERC1155Vaults[i], chainid); } vm.stopBroadcast(); } - - function registerByTimelock( - address registerTo, - string memory name, - address addr, - uint64 chainId - ) - internal - { - AddressManager(registerTo).setAddress(chainId, bytes32(bytes(name)), addr); - console2.log("> ", name, "@", registerTo); - console2.log("\t addr : ", addr); - } }