common

package
v0.1.102 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArgGasLimit             = "gas-limit"
	ArgChainID              = "chain-id"
	ArgPrivateKey           = flag.PrivateKey
	ArgValue                = "value"
	ArgRPCURL               = flag.RPCURL
	ArgBridgeAddress        = "bridge-address"
	ArgRollupManagerAddress = "rollup-manager-address"
	ArgDestNetwork          = "destination-network"
	ArgDestAddress          = "destination-address"
	ArgForceUpdate          = "force-update-root"
	ArgCallData             = "call-data"
	ArgCallDataFile         = "call-data-file"
	ArgTimeout              = "transaction-receipt-timeout"
	ArgDepositCount         = "deposit-count"
	ArgDepositNetwork       = "deposit-network"
	ArgRollupID             = "rollup-id"
	ArgCompleteMT           = "complete-merkle-tree"
	ArgBridgeServiceURL     = "bridge-service-url"
	ArgFileName             = "file-name"
	ArgL2ClaimsFileName     = "l2-claims-file"
	ArgL2DepositsFileName   = "l2-deposits-file"
	ArgL2NetworkID          = "l2-network-id"
	ArgFromBlock            = "from-block"
	ArgToBlock              = "to-block"
	ArgFilterSize           = "filter-size"
	ArgTokenAddress         = "token-address"
	ArgGlobalIndex          = "global-index"
	ArgDryRun               = "dry-run"
	ArgGasPrice             = "gas-price"
	ArgBridgeMappings       = "bridge-service-map"
	ArgBridgeLimit          = "bridge-limit"
	ArgBridgeOffset         = "bridge-offset"
	ArgWait                 = "wait"
	ArgConcurrency          = "concurrency"
	ArgInsecure             = "insecure"
	ArgLegacy               = "legacy"
	ArgProofGER             = "proof-ger"
	ArgProofL1InfoTreeIndex = "proof-l1-info-tree-index"
)
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 (
	ErrNotReadyForClaim      = errors.New("the claim transaction is not yet ready to be claimed, try again in a few blocks")
	ErrDepositAlreadyClaimed = errors.New("the claim transaction has already been claimed")
)

Claim-related error sentinels

View Source
var (
	BridgeService  bridge_service.BridgeService
	BridgeServices = make(map[uint32]bridge_service.BridgeService)
)
View Source
var InputArgs = UlxlyArgs{}

InputArgs is the global instance of UlxlyArgs

Functions

func AddTransactionFlags

func AddTransactionFlags(cmd *cobra.Command)

AddTransactionFlags adds the common transaction flags shared by bridge and claim commands. These flags are needed for any command that sends transactions.

func Check

func Check(roots []common.Hash, leaf common.Hash, position uint32, siblings [32]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 ComputeRoot

func ComputeRoot(leafHash common.Hash, smtProof [32]common.Hash, index uint32, height uint8) common.Hash

ComputeRoot computes the root hash given a leaf, proof siblings, index, and height

func CreateEthClient

func CreateEthClient(ctx context.Context, rpcURL string) (*ethclient.Client, error)

CreateEthClient creates either a secure or insecure client based on the Insecure flag

func CreateInsecureEthClient

func CreateInsecureEthClient(rpcURL string) (*ethclient.Client, error)

CreateInsecureEthClient creates an Ethereum client with TLS certificate verification disabled

func DecodeGlobalIndex

func DecodeGlobalIndex(globalIndex *big.Int) (bool, uint32, uint32, error)

DecodeGlobalIndex decodes a global index into its components

func GenerateEmptyHashes

func GenerateEmptyHashes(height uint8) []common.Hash

GenerateEmptyHashes generates empty hashes for the incremental Merkle tree

func GenerateTransactionPayload

func GenerateTransactionPayload(ctx context.Context, client *ethclient.Client, ulxlyInputArgBridge string, ulxlyInputArgPvtKey string, ulxlyInputArgGasLimit uint64, ulxlyInputArgDestAddr string, ulxlyInputArgChainID string) (bridgeV2 *ulxly.Ulxly, toAddress ethcommon.Address, opts *bind.TransactOpts, err error)

GenerateTransactionPayload generates the transaction payload for bridge operations

func GenerateZeroHashes

func GenerateZeroHashes(height uint8) []common.Hash

GenerateZeroHashes generates zero hashes for the incremental Merkle tree https://eth2book.info/capella/part2/deposits-withdrawals/contract/

func GetBridgeServiceURLs

func GetBridgeServiceURLs() (map[uint32]string, error)

GetBridgeServiceURLs returns a map of network IDs to bridge service URLs

func GetDeposit

func GetDeposit(depositNetwork, depositCount uint32) (*bridge_service.Deposit, error)

GetDeposit retrieves a deposit and checks if it's ready for claiming.

func GetDepositWhenReadyForClaim

func GetDepositWhenReadyForClaim(depositNetwork, depositCount uint32, wait time.Duration) (*bridge_service.Deposit, error)

GetDepositWhenReadyForClaim waits for a deposit to be ready for claiming.

func GetMerkleProofsExitRoots

func GetMerkleProofsExitRoots(bridgeService bridge_service.BridgeService, deposit bridge_service.Deposit, proofGERHash string, l1InfoTreeIndex uint32) (*bridge_service.Proof, error)

GetMerkleProofsExitRoots retrieves Merkle proofs and exit roots for a deposit.

func GetSiblingLeafNumber

func GetSiblingLeafNumber(leafNumber, level uint32) uint32

GetSiblingLeafNumber returns the sibling number of a given number at a specified level in an incremental Merkle tree.

In an incremental Merkle tree, each node has a sibling node at each level of the tree. The sibling node can be determined by flipping the bit at the current level and setting all bits to the right of the current level to 1. This function calculates the sibling number based on the deposit number and the specified level.

Parameters: - LeafNumber: the original number for which the sibling is to be found. - level: the level in the Merkle tree at which to find the sibling.

The logic works as follows: 1. `1 << level` creates a binary number with a single 1 bit at the position corresponding to the level. 2. `LeafNumber ^ (1 << level)` flips the bit at the position corresponding to the level in the LeafNumber. 3. `(1 << level) - 1` creates a binary number with all bits to the right of the current level set to 1. 4. `| ((1 << level) - 1)` ensures that all bits to the right of the current level are set to 1 in the result.

The function effectively finds the sibling deposit number at each level of the Merkle tree by manipulating the bits accordingly.

func HashDeposit

func HashDeposit(deposit *ulxly.UlxlyBridgeEvent) common.Hash

HashDeposit creates the leaf hash value for a particular deposit

func LogAndReturnJSONError

func LogAndReturnJSONError(ctx context.Context, client *ethclient.Client, tx *types.Transaction, opts *bind.TransactOpts, err error) error

LogAndReturnJSONError logs and returns a JSON-RPC error with additional context.

func ParseBridgeDepositCount

func ParseBridgeDepositCount(logs []types.Log, bridgeContract *ulxly.Ulxly) (uint32, error)

ParseBridgeDepositCount parses the deposit count from bridge transaction logs.

func ParseDepositCountFromTransaction

func ParseDepositCountFromTransaction(ctx context.Context, client *ethclient.Client, txHash ethcommon.Hash, bridgeContract *ulxly.Ulxly) (uint32, error)

ParseDepositCountFromTransaction extracts the deposit count from a bridge transaction receipt.

func PrepInputs

func PrepInputs(cmd *cobra.Command, _ []string) (err error)

PrepInputs prepares common inputs for ulxly commands. It loads RPC URL and private key from environment/config if not set via flags, then validates and processes all inputs.

func WaitMineTransaction

func WaitMineTransaction(ctx context.Context, client *ethclient.Client, tx *types.Transaction, txTimeout uint64) error

WaitMineTransaction waits for a transaction to be mined

Types

type GetEvent

type GetEvent struct {
	URL                            string
	FromBlock, ToBlock, FilterSize uint64
	Insecure                       bool
}

GetEvent holds options for retrieving events

func (*GetEvent) AddFlags

func (o *GetEvent) AddFlags(cmd *cobra.Command)

AddFlags adds event retrieval flags to a command

type GetSmcOptions

type GetSmcOptions struct {
	BridgeAddress string
}

GetSmcOptions holds options for smart contract retrieval

func (*GetSmcOptions) AddFlags

func (o *GetSmcOptions) AddFlags(cmd *cobra.Command)

AddFlags adds smart contract option flags to a command

type GetVerifyBatchesOptions

type GetVerifyBatchesOptions struct {
	RollupManagerAddress string
}

GetVerifyBatchesOptions holds options for verify batches retrieval

func (*GetVerifyBatchesOptions) AddFlags

func (o *GetVerifyBatchesOptions) AddFlags(cmd *cobra.Command)

AddFlags adds verify batches option flags to a command

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(leaf common.Hash, position uint32)

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 JSONError

type JSONError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

JSONError represents a JSON-RPC error

type Proof

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

type RollupsProof

type RollupsProof struct {
	Siblings [TreeDepth]common.Hash
	Root     common.Hash
	RollupID uint32
	LeafHash common.Hash
}

func ComputeSiblings

func ComputeSiblings(rollupID uint32, leaves []common.Hash, height uint8) (*RollupsProof, error)

ComputeSiblings computes the siblings for a given rollup ID and leaves

type UlxlyArgs

type UlxlyArgs struct {
	GasLimit             uint64
	ChainID              string
	PrivateKey           string
	AddressOfPrivateKey  string
	Value                string
	RPCURL               string
	BridgeAddress        string
	DestNetwork          uint32
	DestAddress          string
	TokenAddress         string
	ForceUpdate          bool
	CallData             string
	CallDataFile         string
	Timeout              uint64
	DepositCount         uint32
	DepositNetwork       uint32
	BridgeServiceURL     string
	GlobalIndex          string
	GasPrice             string
	DryRun               bool
	BridgeServiceURLs    []string
	BridgeLimit          int
	BridgeOffset         int
	Wait                 time.Duration
	Concurrency          uint
	Insecure             bool
	Legacy               bool
	ProofGER             string
	ProofL1InfoTreeIndex uint32
}

UlxlyArgs holds the arguments for ulxly commands

Jump to

Keyboard shortcuts

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