From 9fc3cb1cfdf7f61a7061407b5d955b22a5ffcaf2 Mon Sep 17 00:00:00 2001 From: Mathis Date: Wed, 18 Sep 2024 02:22:48 +0800 Subject: [PATCH] Update espresso-sequencer-go with new LC ABI (#230) * Update espresso-sequencer-go with new LC ABI Instead of using the block height from the first snapshot after the height in the justification it uses the latest height in the LC contract. Currently not 100% convinced about correctness but also believe it should work because any newer tree still contains the header of interest. * Undo LC ABI changes We're not comfortable with the previous change because making a proof w.r.t to the newest finalized state may cause issues if the batch poster is lagging behind. This is currently not easy to test so we decided to revert back to the old flow. * Use tag of espresso-sequencer-go --- arbnode/hotshot_reader.go | 70 --------------------------------------- go.mod | 2 +- go.sum | 4 +-- 3 files changed, 3 insertions(+), 73 deletions(-) delete mode 100644 arbnode/hotshot_reader.go diff --git a/arbnode/hotshot_reader.go b/arbnode/hotshot_reader.go deleted file mode 100644 index cde521d7c2..0000000000 --- a/arbnode/hotshot_reader.go +++ /dev/null @@ -1,70 +0,0 @@ -package arbnode - -import ( - "fmt" - "math/big" - - "github.com/EspressoSystems/espresso-sequencer-go/hotshot" - espressoTypes "github.com/EspressoSystems/espresso-sequencer-go/types" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/log" -) - -type HotShotReader struct { - HotShot hotshot.Hotshot -} - -func NewHotShotReader(hotShotAddr common.Address, l1client bind.ContractBackend) (*HotShotReader, error) { - hotshot, err := hotshot.NewHotshot(hotShotAddr, l1client) - if err != nil { - return nil, err - } - - return &HotShotReader{ - HotShot: *hotshot, - }, nil -} - -// L1HotShotCommitmentFromHeight returns a HotShot commitments to a sequencer block -// This is used in the derivation pipeline to validate sequencer batches in Espresso mode -func (h *HotShotReader) L1HotShotCommitmentFromHeight(blockHeight uint64) (*espressoTypes.Commitment, error) { - var comm espressoTypes.Commitment - // Check if the requested commitments are even available yet on L1. - contractBlockHeight, err := h.HotShot.HotshotCaller.BlockHeight(nil) - if err != nil { - return nil, err - } - if contractBlockHeight.Cmp(big.NewInt(int64(blockHeight))) < 0 { - return nil, fmt.Errorf("commitment at block height %d is unavailable (current contract block height %d)", blockHeight, contractBlockHeight) - } - - commAsInt, err := h.HotShot.HotshotCaller.Commitments(nil, big.NewInt(int64(blockHeight))) - if err != nil { - return nil, err - } - if commAsInt.Cmp(big.NewInt(0)) == 0 { - // A commitment of 0 indicates that this commitment hasn't been set yet in the contract. - // Since we checked the contract block height above, this can only happen if there was - // a reorg on L1 just now. In this case, return an error rather than reporting - // definitive commitments. The caller will retry and we will succeed eventually when we - // manage to get a consistent snapshot of the L1. - // - // Note that in all other reorg cases, where the L1 reorgs but we read a nonzero - // commitment, we are fine, since the HotShot contract will only ever record a single - // ledger, consistent across all L1 forks, determined by HotShot consensus. The only - // question is whether the recorded ledger extends far enough for the commitments we're - // trying to read on the current fork of L1. - return nil, fmt.Errorf("read 0 for commitment %d at block height %d, this indicates an L1 reorg", blockHeight, contractBlockHeight) - } - - comm, err = espressoTypes.CommitmentFromUint256(espressoTypes.NewU256().SetBigInt(commAsInt)) - - if err != nil { - return nil, err - } - - log.Info("Sucessfully read commitment", "blockHeight", blockHeight, "commitment", commAsInt.String()) - - return &comm, nil -} diff --git a/go.mod b/go.mod index 99f176c4e4..7091f55055 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ replace github.com/VictoriaMetrics/fastcache => ./fastcache replace github.com/ethereum/go-ethereum => ./go-ethereum require ( - github.com/EspressoSystems/espresso-sequencer-go v0.0.23 + github.com/EspressoSystems/espresso-sequencer-go v0.0.24 github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible github.com/Shopify/toxiproxy v2.1.4+incompatible github.com/alicebob/miniredis/v2 v2.32.1 diff --git a/go.sum b/go.sum index 11b47d3adc..925d55ce3f 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,8 @@ github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3 github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/EspressoSystems/espresso-sequencer-go v0.0.23 h1:3fvNU1fvoH6eBZFleaUGl6AVcWhd+H3/paKHnYHKfdM= -github.com/EspressoSystems/espresso-sequencer-go v0.0.23/go.mod h1:BbU8N23RGl45QXSf/bYc8OQ8TG/vlMaPC1GU1acqKmc= +github.com/EspressoSystems/espresso-sequencer-go v0.0.24 h1:VjV4dcA46UaIqmqCvwH5zF3IolZ7U7A7teldr2/gj5k= +github.com/EspressoSystems/espresso-sequencer-go v0.0.24/go.mod h1:BbU8N23RGl45QXSf/bYc8OQ8TG/vlMaPC1GU1acqKmc= github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible h1:1G1pk05UrOh0NlF1oeaaix1x8XzrfjIDK47TY0Zehcw= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=