ulxly

package
v0.1.62 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TreeDepth of 32 is pulled directly from the
	// _DEPOSIT_CONTRACT_TREE_DEPTH from the smart contract. We
	// could make this a variable as well
	// https://github.com/0xPolygonHermez/zkevm-contracts/blob/54f58c8b64806429bc4d5c52248f29cf80ba401c/contracts/v2/lib/DepositContractBase.sol#L15
	TreeDepth = 32
)

Variables

View Source
var EmptyProofCmd = &cobra.Command{
	Use:   "empty-proof",
	Short: "print an empty proof structure",
	Long: `Use this command to print an empty proof response that's filled with
zero-valued siblings like
0x0000000000000000000000000000000000000000000000000000000000000000. This
can be useful when you need to submit a dummy proof.`,
	Args:    cobra.NoArgs,
	PreRunE: checkProofArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		p := new(Proof)

		e := generateEmptyHashes(TreeDepth)
		copy(p.Siblings[:], e)
		fmt.Println(p.String())
		return nil
	},
}
View Source
var ProofCmd = &cobra.Command{
	Use:     "proof",
	Short:   "generate a merkle proof",
	Long:    proofUsage,
	Args:    cobra.NoArgs,
	PreRunE: checkProofArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		rawDepositData, err := getInputData(cmd, args)
		if err != nil {
			return err
		}
		return readDeposits(rawDepositData)
	},
}
View Source
var ULxLyCmd = &cobra.Command{
	Use:   "ulxly",
	Short: "Utilities for interacting with the lxly bridge",
	Long:  "These are low level tools for directly scanning bridge events and constructing proofs.",
	Args:  cobra.NoArgs,
}
View Source
var ZeroProofCmd = &cobra.Command{
	Use:   "zero-proof",
	Short: "print a proof structure with the zero hashes",
	Long: `Use this command to print a proof response that's filled with the zero
hashes. This values are very helpful for debugging because it would
tell you how populated the tree is and roughly which leaves and
siblings are empty. It's also helpful for sanity checking a proof
response to understand if the hashed value is part of the zero hashes
or if it's actually an intermediate hash.`,
	Args:    cobra.NoArgs,
	PreRunE: checkProofArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		p := new(Proof)

		e := generateZeroHashes(TreeDepth)
		copy(p.Siblings[:], e)
		fmt.Println(p.String())
		return nil
	},
}

Functions

This section is empty.

Types

type BridgeDeposits

type BridgeDeposits struct {
	Deposit []struct {
		LeafType      int    `json:"leaf_type"`
		OrigNet       int    `json:"orig_net"`
		OrigAddr      string `json:"orig_addr"`
		Amount        string `json:"amount"`
		DestNet       int    `json:"dest_net"`
		DestAddr      string `json:"dest_addr"`
		BlockNum      string `json:"block_num"`
		DepositCnt    string `json:"deposit_cnt"`
		NetworkID     int    `json:"network_id"`
		TxHash        string `json:"tx_hash"`
		ClaimTxHash   string `json:"claim_tx_hash"`
		Metadata      string `json:"metadata"`
		ReadyForClaim bool   `json:"ready_for_claim"`
		GlobalIndex   string `json:"global_index"`
	} `json:"deposits"`
	TotalCnt string `json:"total_cnt"`
}

type BridgeProof

type BridgeProof struct {
	Proof struct {
		MerkleProof       []string `json:"merkle_proof"`
		RollupMerkleProof []string `json:"rollup_merkle_proof"`
		MainExitRoot      string   `json:"main_exit_root"`
		RollupExitRoot    string   `json:"rollup_exit_root"`
	} `json:"proof"`
}

type IMT

type IMT struct {
	Branches   map[uint32][]common.Hash
	Leaves     map[uint32]common.Hash
	Roots      []common.Hash
	ZeroHashes []common.Hash
	Proofs     map[uint32]Proof
}

func (*IMT) AddLeaf

func (s *IMT) AddLeaf(deposit *ulxly.UlxlyBridgeEvent)

AddLeaf will take a given deposit and add it to the collection of leaves. It will also update the

func (*IMT) GetProof

func (s *IMT) GetProof(depositNum uint32) Proof

GetProof will return an object containing the proof data necessary for verification

func (*IMT) GetRoot

func (s *IMT) GetRoot(depositNum uint32) common.Hash

GetRoot will return the root for a particular deposit

func (*IMT) Init

func (s *IMT) Init()

Init will allocate the objects in the IMT

type Proof

type Proof struct {
	Siblings     [TreeDepth]common.Hash
	Root         common.Hash
	DepositCount uint32
	LeafHash     common.Hash
}

func (*Proof) Check

func (p *Proof) Check(roots []common.Hash) (common.Hash, error)

Check is a sanity check of a proof in order to make sure that the proof that was generated creates a root that we recognize. This was useful while testing in order to avoid verifying that the proof works or doesn't work onchain

func (*Proof) String

func (p *Proof) String() string

String will create the json representation of the proof

Jump to

Keyboard shortcuts

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