Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3176b75
add validator hash to rollkit Header
Dec 21, 2023
318785d
abci commit compatible
Dec 22, 2023
aeca8d7
signing byte for a rollkit header should be CometBFT Vote
Dec 22, 2023
2e91b37
validator hash in header
Dec 22, 2023
9ca53e8
update app hash in state when commit block
Dec 22, 2023
1e04170
validator hash serialization
Dec 22, 2023
2a16bdd
fix failed test
Dec 22, 2023
86638fb
add test
catShaark Dec 22, 2023
d468663
add validator hash to header in GetFirstSignedHeader
Dec 24, 2023
8d5c65e
Merge branch 'main' into jtmb-ibc
vuong177 Dec 27, 2023
6254cdb
tidy
Dec 28, 2023
6d7c9b5
Merge branch 'main' into jtmb-ibc
catShaark Jan 4, 2024
d5e9d80
fix: adapt test utils to pass light.Verify
damiannolan Jan 17, 2024
087ee4e
Merge pull request #1 from damiannolan/damian/aditya-rollkit-abci-hea…
vuong177 Jan 18, 2024
a4868e5
merge with main
Jan 18, 2024
386a7c6
utils : fix incorrect voting power when GetRamdonValset
Jan 18, 2024
c69c2ca
linting
Jan 19, 2024
d0b959f
Merge branch 'main' into jtmb-ibc
vuong177 Jan 19, 2024
8e57aa8
Update node/full_client.go
vuong177 Jan 22, 2024
ea736e7
nits: check empty Validators
Jan 22, 2024
a956aa3
Merge branch 'main' into jtmb-ibc
vuong177 Jan 22, 2024
7768eec
nit
Jan 22, 2024
4acf85f
Merge branch 'main' into jtmb-ibc
vuong177 Jan 23, 2024
ac4b0da
change two defaults to fix go relayer compatibility
Jan 27, 2024
ee19155
attempt fix for ibc
S1nus Feb 1, 2024
84c33a0
set nextvalsethash
S1nus Feb 1, 2024
30147e6
Merge pull request #3 from S1nus/jtmb-ibc
catShaark Feb 1, 2024
8644cec
merge upstream
S1nus Feb 1, 2024
525c062
Merge pull request #4 from S1nus/jtmb-ibc
vuong177 Feb 1, 2024
fd1950a
Merge branch 'main' into jtmb-ibc
catShaark Feb 2, 2024
9012449
Update node/full_client.go
vuong177 Feb 4, 2024
7e66f50
Merge branch 'main' into jtmb-ibc
vuong177 Feb 7, 2024
4bdeee0
remove duplicate update valset
vuong177 Feb 7, 2024
b01b6be
Update types/header.go
vuong177 Feb 7, 2024
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
21 changes: 11 additions & 10 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func NewManager(
return nil, err
}

exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp, eventBus, logger, execMetrics)
exec := state.NewBlockExecutor(proposerAddress, genesis.ChainID, mempool, proxyApp, eventBus, logger, execMetrics, valSet.Hash())
if s.LastBlockHeight+1 == uint64(genesis.InitialHeight) {
res, err := exec.InitChain(genesis)
if err != nil {
Expand Down Expand Up @@ -633,11 +633,10 @@ func (m *Manager) getRemainingSleep(start time.Time) time.Duration {
}

func (m *Manager) getCommit(header types.Header) (*types.Commit, error) {
headerBytes, err := header.MarshalBinary()
if err != nil {
return nil, err
}
sign, err := m.proposerKey.Sign(headerBytes)
// note: for compatibility with tendermint light client
consensusVote := header.MakeCometBFTVote()

sign, err := m.proposerKey.Sign(consensusVote)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -708,6 +707,9 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}
m.logger.Debug("block info", "num_tx", len(block.Data.Txs))

block.SignedHeader.Validators = m.validatorSet
block.SignedHeader.ValidatorHash = m.validatorSet.Hash()
Comment thread
gupadhyaya marked this conversation as resolved.
Resolved

/*
here we set the SignedHeader.DataHash, and SignedHeader.Commit as a hack
to make the block pass ValidateBasic() when it gets called by applyBlock on line 681
Expand All @@ -731,8 +733,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {
}
}

block.SignedHeader.Validators = m.validatorSet

newState, responses, err := m.applyBlock(ctx, block)
if err != nil {
if ctx.Err() != nil {
Expand All @@ -755,7 +755,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {

// set the commit to current block's signed header
block.SignedHeader.Commit = *commit

// Validate the created block before storing
if err := m.executor.Validate(m.lastState, block); err != nil {
return fmt.Errorf("failed to validate block: %w", err)
Expand All @@ -778,10 +777,12 @@ func (m *Manager) publishBlock(ctx context.Context) error {
m.pendingBlocks.addPendingBlock(block)

// Commit the new state and block which writes to disk on the proxy app
_, _, err = m.executor.Commit(ctx, newState, block, responses)
appHash, _, err := m.executor.Commit(ctx, newState, block, responses)
if err != nil {
return err
}
// Update app hash in state
newState.AppHash = appHash
Comment thread
vuong177 marked this conversation as resolved.
Resolved

// SaveBlockResponses commits the DB tx
err = m.store.SaveBlockResponses(ctx, blockHeight, responses)
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const (
DefaultListenAddress = "/ip4/0.0.0.0/tcp/7676"
// Version is the current rollkit version
// Please keep updated with each new release
Version = "0.12.0"
Version = "0.38.5"
)

// DefaultNodeConfig keeps default values of NodeConfig
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ require (
github.com/quic-go/quic-go v0.39.4 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
Expand Down
12 changes: 10 additions & 2 deletions node/full_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,15 @@ func (c *FullClient) Commit(ctx context.Context, height *int64) (*ctypes.ResultC
if err != nil {
return nil, err
}
commit := com.ToABCICommit(heightValue, b.Hash())

// we should have a single validator
if len(b.SignedHeader.Validators.Validators) == 0 {
return nil, errors.New("empty validator set found in block")
}

val := b.SignedHeader.Validators.Validators[0].Address
Comment thread
vuong177 marked this conversation as resolved.
Resolved
commit := com.ToABCICommit(heightValue, b.Hash(), val, b.SignedHeader.Time())

block, err := abciconv.ToABCIBlock(b)
if err != nil {
return nil, err
Expand Down Expand Up @@ -761,7 +769,7 @@ func (c *FullClient) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
EarliestAppHash: cmbytes.HexBytes(initial.SignedHeader.AppHash),
EarliestBlockHeight: int64(initial.Height()),
EarliestBlockTime: initial.Time(),
CatchingUp: true, // the client is always syncing in the background to the latest height
CatchingUp: false, // hard-code this to "false" to pass Go IBC relayer's legacy encoding check
Comment thread
gupadhyaya marked this conversation as resolved.
Resolved
},
ValidatorInfo: ctypes.ValidatorInfo{
Address: validator.Address,
Expand Down
74 changes: 74 additions & 0 deletions node/full_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"

"github.com/cometbft/cometbft/light"

"github.com/rollkit/rollkit/config"
test "github.com/rollkit/rollkit/test/log"
"github.com/rollkit/rollkit/test/mocks"
"github.com/rollkit/rollkit/types"
abciconv "github.com/rollkit/rollkit/types/abci"

cmtmath "github.com/cometbft/cometbft/libs/math"
)

var expectedInfo = &abci.ResponseInfo{
Expand Down Expand Up @@ -380,6 +384,76 @@ func TestGetCommit(t *testing.T) {
})
}

func TestCometBFTLightClientCompability(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
mockApp, rpc := getRPC(t)
mockApp.On("FinalizeBlock", mock.Anything, mock.Anything).Return(finalizeBlockResponse)
mockApp.On("Commit", mock.Anything, mock.Anything).Return(&abci.ResponseCommit{}, nil)

// creat 3 consecutive signed blocks
block1, privKey := types.GetRandomBlockWithKey(1, 1, nil)

block2 := types.GetRandomNextBlock(block1, privKey, []byte{}, 2)

block3 := types.GetRandomNextBlock(block2, privKey, []byte{}, 3)

blocks := []*types.Block{block1, block2, block3}

// start the node for testing
err := rpc.node.Start()
require.NoError(err)
defer func() {
assert.NoError(rpc.node.Stop())
}()
ctx := context.Background()

// save the 3 blocks
for _, b := range blocks {
err = rpc.node.Store.SaveBlock(ctx, b, &b.SignedHeader.Commit)
rpc.node.Store.SetHeight(ctx, b.Height())
require.NoError(err)
}

// Check if the block header provided by rpc.Commit() can be verified using tendermint light client
t.Run("checking rollkit ABCI header verifiability", func(t *testing.T) {
var (
trustingPeriod = 3 * time.Hour
trustLevel = cmtmath.Fraction{Numerator: 2, Denominator: 1}
maxClockDrift = 10 * time.Second
)

// trusted header to verify against
var trustedHeader cmtypes.SignedHeader
setTrustedHeader := false
// valset of single sequencer is constant
fixedValSet := block1.SignedHeader.Validators

// for each block (except block 1), verify it's ABCI header with previous block's ABCI header as trusted header
for _, b := range blocks {
h := int64(b.Height())
commit, err := rpc.Commit(context.Background(), &h)
require.NoError(err)
require.NotNil(commit)
require.NotNil(commit.SignedHeader)
assert.Equal(h, commit.Height)

// if there's no trusted header to verify against, set trusted header and skip verifying
if !setTrustedHeader {
trustedHeader = commit.SignedHeader
setTrustedHeader = true
continue
}

// verify the ABCI header
err = light.Verify(&trustedHeader, fixedValSet, &commit.SignedHeader, fixedValSet, trustingPeriod, b.Time(), maxClockDrift, trustLevel)
require.NoError(err, "failed to pass light.Verify()")

trustedHeader = commit.SignedHeader
}
})
}

func TestBlockSearch(t *testing.T) {
require := require.New(t)
assert := assert.New(t)
Expand Down
89 changes: 47 additions & 42 deletions proto/rollkit/rollkit.proto
Original file line number Diff line number Diff line change
@@ -1,80 +1,85 @@
syntax = "proto3";
package rollkit;
option go_package = "github.com/rollkit/rollkit/types/pb/rollkit";

import "tendermint/types/validator.proto";

option go_package = "github.com/rollkit/rollkit/types/pb/rollkit";

// Version captures the consensus rules for processing a block in the blockchain,
// including all blockchain data structures and the rules of the application's
// state transition machine.
// This is equivalent to the tmversion.Consensus type in Tendermint.
message Version {
uint64 block = 1;
uint64 app = 2;
uint64 block = 1;
uint64 app = 2;
}

message Header {
// Block and App version
Version version = 1;
// Block and App version
Version version = 1;

// Block height
uint64 height = 2;

// Block height
uint64 height = 2;
// Block creation time
uint64 time = 3;

// Block creation time
uint64 time = 3;
// Previous block info
bytes last_header_hash = 4;

// Previous block info
bytes last_header_hash = 4;
// Commit from aggregator(s) from the last block
bytes last_commit_hash = 5;

// Commit from aggregator(s) from the last block
bytes last_commit_hash = 5;
// Block.Data root aka Transactions
bytes data_hash = 6;

// Block.Data root aka Transactions
bytes data_hash = 6;
// Consensus params for current block
bytes consensus_hash = 7;

// Consensus params for current block
bytes consensus_hash = 7;
// State after applying txs from the current block
bytes app_hash = 8;

// State after applying txs from the current block
bytes app_hash = 8;
// Root hash of all results from the txs from the previous block.
// This is ABCI specific but smart-contract chains require some way of committing
// to transaction receipts/results.
bytes last_results_hash = 9;

// Root hash of all results from the txs from the previous block.
// This is ABCI specific but smart-contract chains require some way of committing
// to transaction receipts/results.
bytes last_results_hash = 9;
// Original proposer of the block
// Note that the address can be derived from the pubkey which can be derived
// from the signature when using secp256k.
// We keep this in case users choose another signature format where the
// pubkey can't be recovered by the signature (e.g. ed25519).
bytes proposer_address = 10;

// Original proposer of the block
// Note that the address can be derived from the pubkey which can be derived
// from the signature when using secp256k.
// We keep this in case users choose another signature format where the
// pubkey can't be recovered by the signature (e.g. ed25519).
bytes proposer_address = 10;
// validatorhash for compatibility with tendermint light client.
bytes validator_hash = 11;

// Chain ID the block belongs to
string chain_id = 11;
// Chain ID the block belongs to
string chain_id = 12;
}

message Commit {
repeated bytes signatures = 1;
repeated bytes signatures = 1;
}

message SignedHeader {
Header header = 1;
Commit commit = 2;
tendermint.types.ValidatorSet validators = 3;
Header header = 1;
Commit commit = 2;
tendermint.types.ValidatorSet validators = 3;
}

message Data {
repeated bytes txs = 1;
repeated bytes intermediate_state_roots = 2;
repeated bytes txs = 1;
repeated bytes intermediate_state_roots = 2;
}

message Block {
SignedHeader signed_header = 1;
Data data = 2;
SignedHeader signed_header = 1;
Data data = 2;
}

message TxWithISRs {
bytes pre_isr = 1;
bytes tx = 2;
bytes post_isr = 3;
bytes pre_isr = 1;
bytes tx = 2;
bytes post_isr = 3;
}
10 changes: 6 additions & 4 deletions state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var ErrAddingValidatorToBased = errors.New("cannot add validators to empty valid
// BlockExecutor creates and applies blocks and maintains state.
type BlockExecutor struct {
proposerAddress []byte
valsetHash []byte
chainID string
proxyApp proxy.AppConnConsensus
mempool mempool.Mempool
Expand All @@ -40,9 +41,10 @@ type BlockExecutor struct {
}

// NewBlockExecutor creates new instance of BlockExecutor.
func NewBlockExecutor(proposerAddress []byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, eventBus *cmtypes.EventBus, logger log.Logger, metrics *Metrics) *BlockExecutor {
func NewBlockExecutor(proposerAddress []byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, eventBus *cmtypes.EventBus, logger log.Logger, metrics *Metrics, valsetHash []byte) *BlockExecutor {
return &BlockExecutor{
proposerAddress: proposerAddress,
valsetHash: valsetHash,
chainID: chainID,
proxyApp: proxyApp,
mempool: mempool,
Expand Down Expand Up @@ -141,7 +143,7 @@ func (e *BlockExecutor) CreateBlock(height uint64, lastCommit *types.Commit, las
Misbehavior: []abci.Misbehavior{},
Height: int64(block.Height()),
Time: block.Time(),
NextValidatorsHash: nil,
NextValidatorsHash: e.valsetHash,
ProposerAddress: e.proposerAddress,
},
)
Expand Down Expand Up @@ -185,7 +187,7 @@ func (e *BlockExecutor) ProcessProposal(
},
Misbehavior: []abci.Misbehavior{},
ProposerAddress: e.proposerAddress,
NextValidatorsHash: nil,
NextValidatorsHash: e.valsetHash,
})
if err != nil {
return false, err
Expand Down Expand Up @@ -362,7 +364,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state types.State, block *t
startTime := time.Now().UnixNano()
finalizeBlockResponse, err := e.proxyApp.FinalizeBlock(ctx, &abci.RequestFinalizeBlock{
Hash: block.Hash(),
NextValidatorsHash: nil,
NextValidatorsHash: e.valsetHash,
ProposerAddress: abciHeader.ProposerAddress,
Height: abciHeader.Height,
Time: abciHeader.Time,
Expand Down
Loading