Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into salt
Browse files Browse the repository at this point in the history
  • Loading branch information
danflo27 committed Jun 6, 2024
2 parents c6db2e9 + 18bcc26 commit 3f8ef07
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 7 deletions.
27 changes: 25 additions & 2 deletions app/extend_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ type VoteExtHandler struct {
oracleKeeper OracleKeeper
bridgeKeeper BridgeKeeper
codec codec.Codec
// cosmosCtx sdk.Context
}

type OracleAttestation struct {
Expand Down Expand Up @@ -168,7 +167,31 @@ func (h *VoteExtHandler) ExtendVoteHandler(ctx sdk.Context, req *abci.RequestExt
}

func (h *VoteExtHandler) VerifyVoteExtensionHandler(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
// TODO: implement the logic to verify the vote extension
var voteExt BridgeVoteExtension
err := json.Unmarshal(req.VoteExtension, &voteExt)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal vote extension: %w", err)
}
// ensure oracle attestations length is less than or equal to the number of attestation requests
attestationRequests, err := h.bridgeKeeper.GetAttestationRequestsByHeight(ctx, uint64(ctx.BlockHeight()-1))
if err != nil {
if !errors.Is(err, collections.ErrNotFound) {
return nil, err
} else if len(voteExt.OracleAttestations) > 0 {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
} else if len(voteExt.OracleAttestations) > len(attestationRequests.Requests) {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
// verify the initial signature size
if len(voteExt.InitialSignature.SignatureA) > 65 || len(voteExt.InitialSignature.SignatureB) > 65 {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}
// verify the valset signature size
if len(voteExt.ValsetSignature.Signature) > 65 {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}

return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil
}

Expand Down
71 changes: 67 additions & 4 deletions app/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"reflect"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -42,10 +43,11 @@ type OracleAttestations struct {
}

type VoteExtTx struct {
BlockHeight int64 `json:"block_height"`
OpAndEVMAddrs OperatorAndEVM `json:"op_and_evm_addrs"`
ValsetSigs ValsetSignatures `json:"valset_sigs"`
OracleAttestations OracleAttestations `json:"oracle_attestations"`
BlockHeight int64 `json:"block_height"`
OpAndEVMAddrs OperatorAndEVM `json:"op_and_evm_addrs"`
ValsetSigs ValsetSignatures `json:"valset_sigs"`
OracleAttestations OracleAttestations `json:"oracle_attestations"`
ExtendedCommitInfo abci.ExtendedCommitInfo `json:"extended_commit_info"`
}

func NewProposalHandler(logger log.Logger, valStore baseapp.ValidatorStore, appCodec codec.Codec, oracleKeeper OracleKeeper, bridgeKeeper BridgeKeeper, stakingKeeper StakingKeeper) *ProposalHandler {
Expand Down Expand Up @@ -122,6 +124,7 @@ func (h *ProposalHandler) PrepareProposalHandler(ctx sdk.Context, req *abci.Requ
OpAndEVMAddrs: operatorAndEvm,
ValsetSigs: valsetSigs,
OracleAttestations: oracleAttestations,
ExtendedCommitInfo: req.LocalLastCommit,
}

bz, err := json.Marshal(injectedVoteExtTx)
Expand All @@ -139,6 +142,66 @@ func (h *ProposalHandler) PrepareProposalHandler(ctx sdk.Context, req *abci.Requ
}

func (h *ProposalHandler) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcessProposal) (*abci.ResponseProcessProposal, error) {
h.logger.Info("@ProcessProposalHandler", "height", req.Height, "voteExtEnableHeight", ctx.ConsensusParams().Abci.VoteExtensionsEnableHeight)
if req.Height > ctx.ConsensusParams().Abci.VoteExtensionsEnableHeight {
var injectedVoteExtTx VoteExtTx
if err := json.Unmarshal(req.Txs[0], &injectedVoteExtTx); err != nil {
h.logger.Error("failed to decode injected vote extension tx", "err", err)
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}
err := baseapp.ValidateVoteExtensions(ctx, h.valStore, req.Height, ctx.ChainID(), injectedVoteExtTx.ExtendedCommitInfo)
if err != nil {
return nil, err
}

operatorAddresses, evmAddresses, err := h.CheckInitialSignaturesFromLastCommit(ctx, injectedVoteExtTx.ExtendedCommitInfo)
if err != nil {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(operatorAddresses, injectedVoteExtTx.OpAndEVMAddrs.OperatorAddresses) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(evmAddresses, injectedVoteExtTx.OpAndEVMAddrs.EVMAddresses) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

valsetOperatorAddresses, valsetTimestamps, valsetSignatures, err := h.CheckValsetSignaturesFromLastCommit(ctx, injectedVoteExtTx.ExtendedCommitInfo)
if err != nil {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(valsetOperatorAddresses, injectedVoteExtTx.ValsetSigs.OperatorAddresses) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(valsetTimestamps, injectedVoteExtTx.ValsetSigs.Timestamps) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(valsetSignatures, injectedVoteExtTx.ValsetSigs.Signatures) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

oracleSigs, oracleSnapshots, oracleOperatorAddresses, err := h.CheckOracleAttestationsFromLastCommit(ctx, injectedVoteExtTx.ExtendedCommitInfo)
if err != nil {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(oracleSigs, injectedVoteExtTx.OracleAttestations.Attestations) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(oracleSnapshots, injectedVoteExtTx.OracleAttestations.Snapshots) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}

if !reflect.DeepEqual(oracleOperatorAddresses, injectedVoteExtTx.OracleAttestations.OperatorAddresses) {
return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_REJECT}, nil
}
}

return &abci.ResponseProcessProposal{Status: abci.ResponseProcessProposal_ACCEPT}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion start_scripts/start_bill.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ echo "$VALIDATOR_JSON" > $NODE2_HOME_DIR/config/validator.json

# Stake Bill as a validator
echo "Staking bill as a validator..."
./layerd tx staking create-validator ~/.layer/bill/config/validator.json --from bill --keyring-backend $KEYRING_BACKEND --keyring-dir ~/.layer/bill --chain-id layer --home ~/.layer/bill
./layerd tx staking create-validator ~/.layer/bill/config/validator.json --from bill --keyring-backend $KEYRING_BACKEND --keyring-dir ~/.layer/bill --chain-id layer --home ~/.layer/bill --gas 300000

# Modify keyring-backend in client.toml for bill
echo "Modifying keyring-backend in client.toml for bill..."
Expand Down

0 comments on commit 3f8ef07

Please sign in to comment.