tee

package
v0.0.0-...-f39f649 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEnclaveStopped = errors.New("Enclave stopped")

Functions

func EncodeBalanceProof

func EncodeBalanceProof(contract common.Address, balance Balance) ([]byte, error)

func EncodeDepositProof

func EncodeDepositProof(contract common.Address, balance Balance) ([]byte, error)

func EncodeTransaction

func EncodeTransaction(contract common.Address, tx Transaction) ([]byte, error)

EncodeTransaction abi-encodes an off-chain transaction. We use abi encoding for consistency even though this message is never used on-chain. Should only be used for signing purposes.

func VerifyBalanceProof

func VerifyBalanceProof(params Parameters, proof BalanceProof) (bool, error)

func VerifyDepositProof

func VerifyDepositProof(params Parameters, proof DepositProof) (bool, error)

func VerifyTransaction

func VerifyTransaction(contract common.Address, tx Transaction) (bool, error)

Types

type Amount

type Amount big.Int

Amount is a big.Int wrapper to allow for json en-decoding.

func (*Amount) GobDecode

func (a *Amount) GobDecode(blob []byte) error

func (*Amount) GobEncode

func (a *Amount) GobEncode() ([]byte, error)

func (Amount) MarshalJSON

func (a Amount) MarshalJSON() ([]byte, error)

func (*Amount) UnmarshalJSON

func (a *Amount) UnmarshalJSON(data []byte) error

type Balance

type Balance struct {
	Epoch   Epoch          `json:"epoch"`   // sol: uint64
	Account common.Address `json:"account"` // sol: address
	Value   *Amount        `json:"value"`   // sol: uint256
}

A Balance states the balance of the user with address Account in the system at epoch Epoch.

Its Solidity struct type is (uint64, address, uint256).

func (*Balance) Clone

func (b *Balance) Clone() Balance

func (*Balance) ToEthBal

func (b *Balance) ToEthBal() bindings.ErdstallBalance

type BalanceProof

type BalanceProof struct {
	Balance Balance `json:"balance"`
	Sig     Sig     `json:"sig"`
}

A BalanceProof is generated by the Enclave at the end of each transaction phase for each account in the system. The Operator has to forward those to the users or risks facing an on-chain challenge.

type Block

type Block struct {
	types.Block
	Receipts types.Receipts
}

A Block is a go-ethereum block together with its receipts. go-ethereum's types.Block type doesn't store the receipts...

func (*Block) GobDecode

func (b *Block) GobDecode(blob []byte) error

func (Block) GobEncode

func (b Block) GobEncode() ([]byte, error)

type DepositProof

type DepositProof struct {
	Balance Balance `json:"balance"`
	Sig     Sig     `json:"sig"`
}

A DepositProof is generated by the Enclave at the end of each deposit phase for each account that made a deposit. The Operator has to forward those to the users or risks facing an on-chain challenge.

type Enclave

type Enclave interface {
	// Init initializes the enclave, generating a new secp256k1 ECDSA key and
	// storing it as the enclave's signing key.
	//
	// It returns the public key derived Ethereum address and attestation of
	// correct initialization of the enclave with the generated address. The
	// attestation can be used to verify the enclave with the TEE vendor.
	//
	// The Operator must deploy the contract with the Enclave's address after
	// calling Init.
	Init() (common.Address, []byte, error)

	// Run should be called by the operator after they deployed the contract to
	// start the Enclave with the given parameters. The call blocks until the
	// Enclave has shut down. It can be told to gracefully shutdown by calling
	// Shutdown.
	//
	// The Enclave verifies the parameters upon receival of the first block.
	Run(Parameters) error

	// ProcessBlocks should be called by the Operator to cause the enclave to
	// process the given block(s), logging deposits and exits.
	//
	// Note that BalanceProofs requires an additional k blocks to be known to
	// the Enclave before it reveals an epoch's balance proofs to the operator.
	// k is a security parameter to guarantee enough PoW depth.
	ProcessBlocks(...*Block) error

	// ProcessTXs should be called by the Operator whenever they receive new
	// transactions from users. After a transaction epoch has finished and an
	// additional k blocks made known to the Enclave, the epoch's balance proofs
	// can be received by calling BalanceProofs.
	ProcessTXs(...*Transaction) error

	// DepositProofs returns the deposit proofs of all deposits made in an epoch
	// at the end of the deposit phase.
	//
	// Note that all blocks of the epoch's deposit phase (+k) need to be known
	// to the Enclave. This call blocks until all necessary blocks are received
	// and processed.
	//
	// It should be called in a loop by the operator.
	DepositProofs() ([]*DepositProof, error)

	// BalanceProofs returns all balance proofs at the end of each transaction
	// phase.
	//
	// Note that all blocks of the epoch's transaction phase (+k) need to be
	// known to the Enclave. This call blocks until all necessary blocks are
	// received and processed.
	//
	// It should be called in a loop by the operator.
	BalanceProofs() ([]*BalanceProof, error)

	// Shutdown signals the Enclave to gracefully shutdown after the next phase
	// is sealed. It will continue receiving transactions and blocks until the
	// last block of the current phase is received via ProcessBlocks.
	//
	// The functions ProcessBlocks, ProcessTXs, DepositProofs and BalanceProofs
	// will return an ErrEnclaveStopped error after the Enclave shut down.
	// The operator should test for this error in their loops around those
	// functions.
	Shutdown()
}

type Epoch

type Epoch = uint64

Epoch is the epoch counter type.

type Parameters

type Parameters struct {
	PowDepth         uint64         // required confirmed block depth
	PhaseDuration    uint64         // number of blocks of one phase (not epoch)
	ResponseDuration uint64         // challenge response grace period for operator at end of exit phase
	InitBlock        uint64         // block at which Erdstall contract was deployed
	TEE              common.Address // Enclave's public key address
	Contract         common.Address // Erdstall contract address
}

func (Parameters) DepositDoneBlock

func (p Parameters) DepositDoneBlock(epoch uint64) uint64

func (Parameters) DepositEpoch

func (p Parameters) DepositEpoch(blockNum uint64) Epoch

DepositEpoch returns the deposit epoch at the given block number.

func (Parameters) DepositStartBlock

func (p Parameters) DepositStartBlock(epoch uint64) uint64

func (Parameters) ExitDoneBlock

func (p Parameters) ExitDoneBlock(epoch uint64) uint64

func (Parameters) ExitEpoch

func (p Parameters) ExitEpoch(blockNum uint64) Epoch

ExitEpoch returns the exit epoch at the given block number.

func (Parameters) FreezingEpoch

func (p Parameters) FreezingEpoch(blockNum uint64) Epoch

FreezingEpoch returns the freezing epoch at the given block number.

func (Parameters) IsChallengeResponsePhase

func (p Parameters) IsChallengeResponsePhase(blockNum uint64) bool

func (Parameters) IsLastPhaseBlock

func (p Parameters) IsLastPhaseBlock(blockNum uint64) bool

IsLastPhaseBlock tells whether this block is the last block of a phase.

func (Parameters) SealedEpoch

func (p Parameters) SealedEpoch(blockNum uint64) Epoch

SealedEpoch returns the sealed epoch at the given block number. It has the same value as `FreezingEpoch`.

func (Parameters) TxDoneBlock

func (p Parameters) TxDoneBlock(epoch uint64) uint64

func (Parameters) TxEpoch

func (p Parameters) TxEpoch(blockNum uint64) Epoch

TxEpoch returns the transaction epoch at the given block number.

type Sig

type Sig []byte

Sig represents an ethereum signature. It is always 65 bytes long.

func (Sig) MarshalJSON

func (s Sig) MarshalJSON() ([]byte, error)

func (*Sig) UnmarshalJSON

func (s *Sig) UnmarshalJSON(data []byte) error

type TextSigner

type TextSigner interface {
	// SignText returns a signature with 'v' value of 0 or 1.
	SignText(account accounts.Account, text []byte) ([]byte, error)
}

A TextSigner can sign messages. It's usually a wallet like an accounts.Wallet

type Transaction

type Transaction struct {
	Nonce     uint64         `json:"nonce"` // starts at 0, each tx must increase by one, across epochs
	Epoch     Epoch          `json:"epoch"`
	Sender    common.Address `json:"sender"`
	Recipient common.Address `json:"recipient"`
	Amount    *Amount        `json:"amount"`
	Sig       Sig            `json:"sig"`
	// contains filtered or unexported fields
}

Transaction is a payment transaction from Sender to Recipient, signed by the Sender. The epoch must match the current transaction epoch.

Nonce tracking allows to send multiple transactions per epoch, each only stating the amount of the individual transaction.

func (*Transaction) Hash

func (t *Transaction) Hash() common.Hash

Hash hashes a transaction.

func (*Transaction) Sign

func (t *Transaction) Sign(contract common.Address, account accounts.Account, w TextSigner) error

Sign signs the transaction with the given account and signer. It checks that the account matches the transaction's sender.

func (*Transaction) SignAlien

func (t *Transaction) SignAlien(contract common.Address, account accounts.Account, w TextSigner) error

SignAlien signs the transaction with the given account and signer, irrespective of who's the transaction's sender. Should only be used in testing.

type Transactor

type Transactor interface {
	Send(*Transaction) error
}

Transactor executes transactions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL