Skip to main content

State

Params

Params is a module-wide configuration structure that stores system parameters and defines overall functioning of the peggy module. Detailed specification for each parameter can be found in the Parameters section.

  • Params: Paramsspace("peggy") -> legacy_amino(params)

Validator Info

Ethereum Address by Validator

Stores each Validator's corresponding delegate Ethereum address indexed by the validator's account address.

keyValueTypeEncoding
[]byte{0x1} + []byte(validatorAddr)Ethereum addresscommon.AddressProtobuf encoded

Validator by Ethereum Address

Stores each Validator's account address indexed by Ethereum address.

keyValueTypeEncoding
[]byte{0xfb} + []byte(ethAddress)Validator addresssdk.ValAddressProtobuf encoded

OutgoingTxBatch

Stored in two possible ways, first with a height and second without (unsafe). Unsafe is used for testing and export and import of state. Currently Peggy.sol is hardcoded to only accept batches with a single token type and only pay rewards in that same token type.

// OutgoingTxBatch represents a batch of transactions going from Peggy to ETH
type OutgoingTxBatch struct {
BatchNonce uint64
BatchTimeout uint64
Transactions []*OutgoingTransferTx
TokenContract string
Block uint64
}
keyValueTypeEncoding
[]byte{0xa} + []byte(tokenContract) + nonce (big endian encoded)A batch of outgoing transactionstypes.OutgoingTxBatchProtobuf encoded

ValidatorSet

This is the validator set of the bridge.

Stored in two possible ways, first with a height and second without (unsafe). Unsafe is used for testing and export and import of state.

// Valset is the Ethereum Bridge Multsig Set, each peggy validator also
// maintains an ETH key to sign messages, these are used to check signatures on
// ETH because of the significant gas savings
type Valset struct {
Nonce uint64
Members []*BridgeValidator
Height uint64
RewardAmount sdkmath.Int
// the reward token in it's Ethereum hex address representation
RewardToken string
}

keyValueTypeEncoding
[]byte{0x2} + nonce (big endian encoded)Validator settypes.ValsetProtobuf encoded

SlashedValsetNonce

The latest validator set slash nonce. This is used to track which validator set needs to be slashed and which already has been.

KeyValueTypeEncoding
[]byte{0xf5}Nonceuint64encoded via big endian

ValsetNonce

The latest validator set nonce, this value is updated on every write.

keyValueTypeEncoding
[]byte{0xf6}Nonceuint64encoded via big endian

Valset Confirmation

When a validator signs over a validator set this is considered a valSetConfirmation, these are saved via the current nonce and the orchestrator address.

// MsgValsetConfirm
// this is the message sent by the validators when they wish to submit their
// signatures over the validator set at a given block height. A validator must
// first call MsgSetEthAddress to set their Ethereum address to be used for
// signing. Then someone (anyone) must make a ValsetRequest the request is
// essentially a messaging mechanism to determine which block all validators
// should submit signatures over. Finally validators sign the validator set,
// powers, and Ethereum addresses of the entire validator set at the height of a
// ValsetRequest and submit that signature with this message.
// -------------
type MsgValsetConfirm struct {
Nonce uint64
Orchestrator string
EthAddress string
Signature string
}
KeyValueTypeEncoding
[]byte{0x3} + (nonce + []byte(AccAddress)Validator Confirmationtypes.MsgValsetConfirmProtobuf encoded

ConfirmBatch

When a validator confirms a batch it is added to the confirm batch store. It is stored using the orchestrator, token contract and nonce as the key.

// MsgConfirmBatch
type MsgConfirmBatch struct {
Nonce uint64
TokenContract string
EthSigner string
Orchestrator string
Signature string
}

KeyValueTypeEncoding
[]byte{0xe1} + []byte(tokenContract) + nonce + []byte(AccAddress)Validator Batch Confirmationtypes.MsgConfirmBatchProtobuf encoded

OrchestratorValidator

When a validator would like to delegate their voting power to another key. The value is stored using the orchestrator address as the key

KeyValueTypeEncoding
[]byte{0xe8} + []byte(AccAddress)Orchestrator address assigned by a validator[]byteProtobuf encoded

EthAddress

A validator has an associated counter chain address.

KeyValueTypeEncoding
[]byte{0x1} + []byte(ValAddress)Ethereum address assigned by a validator[]byteProtobuf encoded

OutgoingTransferTx

Sets an outgoing transactions into the applications transaction pool to be included into a batch.

// OutgoingTransferTx represents an individual send from Peggy to ETH
type OutgoingTransferTx struct {
Id uint64
Sender string
DestAddress string
Erc20Token *ERC20Token
Erc20Fee *ERC20Token
}
KeyValueTypeEncoding
[]byte{0x6} + id (big endian encoded)User created transaction to be included in a batchtypes.OutgoingTransferTxProtobuf encoded

IDS

SlashedBlockHeight

Represents the latest slashed block height. There is always only a singe value stored.

KeyValueTypeEncoding
[]byte{0xf7}Latest height a batch slashing occurreduint64Big endian encoded

TokenContract & Denom

A denom that is originally from a counter chain will be from a contract. The token contract and denom are stored in two ways. First, the denom is used as the key and the value is the token contract. Second, the contract is used as the key, the value is the denom the token contract represents.

KeyValueTypeEncoding
[]byte{0xf3} + []byte(denom)Token contract address[]bytestored in byte format
KeyValueTypeEncoding
[]byte{0xf4} + []byte(tokenContract)Latest height a batch slashing occurred[]bytestored in byte format

LastEventNonce

The last observed event nonce. This is set when TryAttestation() is called. There is always only a single value held in this store.

KeyValueTypeEncoding
[]byte{0xf2}Last observed event nonceuint64Big endian encoded

LastObservedEthereumHeight

This is the last observed height on ethereum. There will always only be a single value stored in this store.

KeyValueTypeEncoding
[]byte{0xf9}Last observed Ethereum Heightuint64Protobuf encoded

Attestation

// Attestation is an aggregate of `claims` that eventually becomes `observed` by
// all orchestrators
// EVENT_NONCE:
// EventNonce a nonce provided by the peggy contract that is unique per event fired
// These event nonces must be relayed in order. This is a correctness issue,
// if relaying out of order transaction replay attacks become possible
// OBSERVED:
// Observed indicates that >67% of validators have attested to the event,
// and that the event should be executed by the peggy state machine
type Attestation struct {
Observed bool
Votes []string
Height uint64
Claim *types.Any
}
KeyValueTypeEncoding
[]byte{0x5} + evenNonce (big endian encoded) + []byte(claimHash)Attestation of occurred events/claimstypes.AttestationProtobuf encoded