rollup

package
v0.0.0-...-70ee9f5 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BatchSizeCircuit = 1 // nbTranfers to batch in a proof
)

Variables

View Source
var (
	// ErrSizeByteSlice memory checking
	ErrSizeByteSlice = errors.New("byte slice size is inconsistent with Account size")

	// ErrNonExistingAccount account not in the database
	ErrNonExistingAccount = errors.New("the account is not in the rollup database")

	// ErrWrongSignature wrong signature
	ErrWrongSignature = errors.New("invalid signature")

	// ErrAmountTooHigh the amount is bigger than the balance
	ErrAmountTooHigh = errors.New("amount is bigger than balance")

	// ErrNonce inconsistent nonce between transfer and account
	ErrNonce = errors.New("incorrect nonce")

	// ErrIndexConsistency the map publicKey(string) -> index(int) gives acces to the account position.
	// Account has a field index, that should match position.
	ErrIndexConsistency = errors.New("account's position should match account's index")
)
View Source
var BatchSize = 10

BatchSize size of a batch of transactions to put in a snark

View Source
var (
	// SizeAccount byte size of a serialized account (5*32bytes)
	// index ∥ nonce ∥ balance ∥ pubkeyX ∥ pubkeyY, each chunk is 32 bytes
	SizeAccount = 160
)

Functions

func Deserialize

func Deserialize(res *Account, data []byte) error

Deserialize deserializes a stream of byte in an account

Types

type Account

type Account struct {
	// contains filtered or unexported fields
}

Account describes a rollup account

func (*Account) Reset

func (ac *Account) Reset()

Reset resets an account

func (*Account) Serialize

func (ac *Account) Serialize() []byte

Serialize serializes the account as a concatenation of 5 chunks of 256 bits one chunk per field (pubKey has 2 chunks), except index and nonce that are concatenated in a single 256 bits chunk index ∥ nonce ∥ balance ∥ pubkeyX ∥ pubkeyY, each chunk is 256 bits

type AccountConstraints

type AccountConstraints struct {
	Index   frontend.Variable // index in the tree
	Nonce   frontend.Variable // nb transactions done so far from this account
	Balance frontend.Variable
	PubKey  eddsa.PublicKey `gnark:"-"`
}

AccountConstraints accounts encoded as constraints

type Circuit

type Circuit struct {

	// list of accounts involved before update and their public keys
	SenderAccountsBefore   [BatchSizeCircuit]AccountConstraints
	ReceiverAccountsBefore [BatchSizeCircuit]AccountConstraints
	PublicKeysSender       [BatchSizeCircuit]eddsa.PublicKey

	// list of accounts involved after update and their public keys
	SenderAccountsAfter   [BatchSizeCircuit]AccountConstraints
	ReceiverAccountsAfter [BatchSizeCircuit]AccountConstraints
	PublicKeysReceiver    [BatchSizeCircuit]eddsa.PublicKey

	// list of transactions
	Transfers [BatchSizeCircuit]TransferConstraints

	// list of proofs corresponding to sender and receiver accounts
	MerkleProofReceiverBefore [BatchSizeCircuit]merkle.MerkleProof
	MerkleProofReceiverAfter  [BatchSizeCircuit]merkle.MerkleProof
	MerkleProofSenderBefore   [BatchSizeCircuit]merkle.MerkleProof
	MerkleProofSenderAfter    [BatchSizeCircuit]merkle.MerkleProof
	LeafReceiver              [BatchSizeCircuit]frontend.Variable
	LeafSender                [BatchSizeCircuit]frontend.Variable

	// list of root hashes
	RootHashesBefore [BatchSizeCircuit]frontend.Variable `gnark:",public"`
	RootHashesAfter  [BatchSizeCircuit]frontend.Variable `gnark:",public"`
}

Circuit "toy" rollup circuit where an operator can generate a proof that he processed some transactions

func (*Circuit) Define

func (circuit *Circuit) Define(api frontend.API) error

Define declares the circuit's constraints

type Operator

type Operator struct {
	State      []byte            // list of accounts: index ∥ nonce ∥ balance ∥ pubkeyX ∥ pubkeyY, each chunk is 256 bits
	HashState  []byte            // Hashed version of the state, each chunk is 256bits: ... ∥ H(index ∥ nonce ∥ balance ∥ pubkeyX ∥ pubkeyY)) ∥ ...
	AccountMap map[string]uint64 // hashmap of all available accounts (the key is the account.pubkey.X), the value is the index of the account in the state
	// contains filtered or unexported fields
}

Operator represents a rollup operator

func NewOperator

func NewOperator(nbAccounts int) Operator

NewOperator creates a new operator. nbAccounts is the number of accounts managed by this operator, h is the hash function for the merkle proofs

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue queue for storing the transfers (fixed size queue)

func NewQueue

func NewQueue(BatchSizeCircuit int) Queue

NewQueue creates a new queue, BatchSizeCircuit is the capacity

type Transfer

type Transfer struct {
	// contains filtered or unexported fields
}

Transfer describe a rollup transfer

func NewTransfer

func NewTransfer(amount uint64, from, to eddsa.PublicKey, nonce uint64) Transfer

NewTransfer creates a new transfer (to be signed)

func (*Transfer) Sign

func (t *Transfer) Sign(priv eddsa.PrivateKey, h hash.Hash) (eddsa.Signature, error)

Sign signs a transaction

func (*Transfer) Verify

func (t *Transfer) Verify(h hash.Hash) (bool, error)

Verify verifies the signature of the transfer. The message to sign is the hash (o.h) of the account.

type TransferConstraints

type TransferConstraints struct {
	Amount         frontend.Variable
	Nonce          frontend.Variable `gnark:"-"`
	SenderPubKey   eddsa.PublicKey   `gnark:"-"`
	ReceiverPubKey eddsa.PublicKey   `gnark:"-"`
	Signature      eddsa.Signature
}

TransferConstraints transfer encoded as constraints

Jump to

Keyboard shortcuts

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