evilwallet

package
v0.0.0-...-1f0f14a Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FaucetRequestSplitNumber defines the number of outputs to split from a faucet request.
	FaucetRequestSplitNumber = 100
)

Variables

This section is empty.

Functions

func SplitBalanceEqually

func SplitBalanceEqually(splitNumber int, balance iotago.BaseToken) []iotago.BaseToken

SplitBalanceEqually splits the balance equally between `splitNumber` outputs.

func WithAccountsWallet

func WithAccountsWallet(wallet *accountwallet.AccountWallet) options.Option[EvilWallet]

func WithClients

func WithClients(urls ...string) options.Option[EvilWallet]

Types

type AliasManager

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

AliasManager is the manager for output aliases.

func NewAliasManager

func NewAliasManager() *AliasManager

NewAliasManager creates and returns a new AliasManager.

func (*AliasManager) AddInputAlias

func (a *AliasManager) AddInputAlias(input *models.Output, aliasName string)

AddInputAlias adds an input alias.

func (*AliasManager) AddInputAliases

func (a *AliasManager) AddInputAliases(inputs []*models.Output, aliases []string) error

AddInputAliases batch adds the inputs their respective aliases.

func (*AliasManager) AddOutputAlias

func (a *AliasManager) AddOutputAlias(output *models.Output, aliasName string)

AddOutputAlias maps the given outputAliasName to output, if there's duplicate outputAliasName, it will be overwritten.

func (*AliasManager) AddOutputAliases

func (a *AliasManager) AddOutputAliases(outputs []*models.Output, aliases []string) error

AddOutputAliases batch adds the outputs their respective aliases.

func (*AliasManager) ClearAliases

func (a *AliasManager) ClearAliases(aliases ScenarioAlias)

ClearAliases clears provided aliases.

func (*AliasManager) ClearAllAliases

func (a *AliasManager) ClearAllAliases()

ClearAllAliases clears all aliases.

func (*AliasManager) GetInput

func (a *AliasManager) GetInput(aliasName string) (*models.Output, bool)

GetInput returns the input for the alias specified.

func (*AliasManager) GetOutput

func (a *AliasManager) GetOutput(aliasName string) *models.Output

GetOutput returns the output for the alias specified.

type ConflictSlice

type ConflictSlice [][]Option

ConflictSlice represents a set of conflict transactions.

type EvilBatch

type EvilBatch [][]ScenarioAlias

func ConflictSetCircle

func ConflictSetCircle(size int) EvilBatch

ConflictSetCircle creates a circular conflict set for a given size, e.g. for size=3, conflict set: A-B-C-A.

func GetScenario

func GetScenario(scenarioName string) (batch EvilBatch, ok bool)

GetScenario returns an evil batch based i=on its name.

func NSpendBatch

func NSpendBatch(nSpent int) EvilBatch

func NoConflictsScenario1

func NoConflictsScenario1() EvilBatch

NoConflictsScenario1 returns batch with no conflicts that is 3 levels deep.

func Scenario1

func Scenario1() EvilBatch

Scenario1 describes two double spends and aggregates them.

func Scenario2

func Scenario2() EvilBatch

Scenario2 is a reflection of UTXO unit test scenario example B - packages/ledgerstate/utxo_dag_test_exampleB.png.

func Scenario3

func Scenario3() EvilBatch

Scenario3 is a reflection of UTXO unit test scenario example C - packages/ledgerstate/utxo_dag_test_exampleC.png.

func Scenario4

func Scenario4() EvilBatch

Scenario4 is a reflection of ledgerstate unit test for conflict confirmation - packages/ledgerstate/ledgerstate_test_SetConflictConfirmed.png.

func Scenario5

func Scenario5() EvilBatch

Scenario5 uses ConflictSetCircle with size 4 and aggregate its outputs.

func Scenario6

func Scenario6() EvilBatch

Scenario6 returns 5 levels deep scenario.

func Scenario7

func Scenario7() EvilBatch

Scenario7 three level deep scenario, with two separate conflict sets aggregated.

func SingleTransactionBatch

func SingleTransactionBatch() EvilBatch

SingleTransactionBatch returns an EvilBatch that is a single transaction.

type EvilScenario

type EvilScenario struct {
	ID string
	// provides a user-friendly way of listing input and output aliases
	ConflictBatch EvilBatch
	// determines whether outputs of the batch  should be reused during the spam to create deep UTXO tree structure.
	Reuse bool
	// specifies the output type of the spam, if not provided, defaults to BasicOutput
	OutputType iotago.OutputType
	// if provided, the outputs from the spam will be saved into this wallet, accepted types of wallet: Reuse, RestrictedReuse.
	// if type == Reuse, then wallet is available for reuse spamming scenarios that did not provide RestrictedWallet.
	OutputWallet *Wallet
	// if provided and reuse set to true, outputs from this wallet will be used for deep spamming, allows for controllable building of UTXO deep structures.
	// if not provided evil wallet will use Reuse wallet if any is available. Accepts only RestrictedReuse wallet type.
	RestrictedInputWallet *Wallet
	// used together with scenario ID to create a prefix for distinct batch alias creation
	BatchesCreated *atomic.Uint64
	// used to determine how many clients are needed to run this scenario, some double spends need more than one client to pass the filter
	NumOfClientsNeeded int
}

func NewEvilScenario

func NewEvilScenario(options ...ScenarioOption) *EvilScenario

func (*EvilScenario) ConflictBatchWithPrefix

func (e *EvilScenario) ConflictBatchWithPrefix() (prefixedBatch EvilBatch, allAliases ScenarioAlias, batchOutputs map[string]types.Empty)

ConflictBatchWithPrefix generates a new conflict batch with scenario prefix created from scenario ID and batch count. BatchOutputs are outputs of the batch that can be reused in deep spamming by collecting them in Reuse wallet.

type EvilWallet

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

EvilWallet provides a user-friendly way to do complicated double spend scenarios.

func NewEvilWallet

func NewEvilWallet(opts ...options.Option[EvilWallet]) *EvilWallet

NewEvilWallet creates an EvilWallet instance.

func (*EvilWallet) AddClient

func (e *EvilWallet) AddClient(clientURL string)

func (*EvilWallet) ClearAliases

func (e *EvilWallet) ClearAliases(aliases ScenarioAlias)

ClearAliases remove only provided aliases from AliasManager.

func (*EvilWallet) ClearAllAliases

func (e *EvilWallet) ClearAllAliases()

ClearAllAliases remove all registered alias names.

func (*EvilWallet) Connector

func (e *EvilWallet) Connector() models.Connector

Connector give access to the EvilWallet connector.

func (*EvilWallet) CreateTransaction

func (e *EvilWallet) CreateTransaction(options ...Option) (*models.PayloadIssuanceData, error)

CreateTransaction creates a transaction based on provided options. If no input wallet is provided, the next non-empty faucet wallet is used. Inputs of the transaction are determined in three ways: 1 - inputs are provided directly without associated alias, 2- alias is provided, and input is already stored in an alias manager, 3 - alias is provided, and there are no inputs assigned in Alias manager, so aliases are assigned to next ready inputs from input wallet.

func (*EvilWallet) GetAccount

func (e *EvilWallet) GetAccount(alias string) (blockhandler.Account, error)

func (*EvilWallet) GetClients

func (e *EvilWallet) GetClients(num int) []models.Client

GetClients returns the given number of clients.

func (*EvilWallet) LastFaucetUnspentOutput

func (e *EvilWallet) LastFaucetUnspentOutput() iotago.OutputID

func (*EvilWallet) NewWallet

func (e *EvilWallet) NewWallet(wType ...WalletType) *Wallet

NewWallet creates a new wallet of the given wallet type.

func (*EvilWallet) NumOfClient

func (e *EvilWallet) NumOfClient() int

func (*EvilWallet) PrepareAccountSpam

func (e *EvilWallet) PrepareAccountSpam(scenario *EvilScenario, strategy *models.IssuancePaymentStrategy) (*models.PayloadIssuanceData, ScenarioAlias, error)

func (*EvilWallet) PrepareAndPostBlock

func (e *EvilWallet) PrepareAndPostBlock(clt models.Client, payload iotago.Payload, congestionResp *apimodels.CongestionResponse, issuer blockhandler.Account) (iotago.BlockID, error)

func (*EvilWallet) PrepareCustomConflicts

func (e *EvilWallet) PrepareCustomConflicts(conflictsMaps []ConflictSlice) (conflictBatch [][]*models.PayloadIssuanceData, err error)

func (*EvilWallet) PrepareCustomConflictsSpam

func (e *EvilWallet) PrepareCustomConflictsSpam(scenario *EvilScenario, strategy *models.IssuancePaymentStrategy) (txsData [][]*models.PayloadIssuanceData, allAliases ScenarioAlias, err error)

func (*EvilWallet) RemoveClient

func (e *EvilWallet) RemoveClient(clientURL string)

func (*EvilWallet) RequestFreshBigFaucetWallet

func (e *EvilWallet) RequestFreshBigFaucetWallet() error

RequestFreshBigFaucetWallet creates a new wallet and fills the wallet with 1000 outputs created from funds requested from the Faucet.

func (*EvilWallet) RequestFreshBigFaucetWallets

func (e *EvilWallet) RequestFreshBigFaucetWallets(numberOfWallets int)

RequestFreshBigFaucetWallets creates n new wallets, each wallet is created from one faucet request and contains 1000 outputs.

func (*EvilWallet) RequestFreshFaucetWallet

func (e *EvilWallet) RequestFreshFaucetWallet() error

RequestFreshFaucetWallet creates a new wallet and fills the wallet with 100 outputs created from funds requested from the Faucet.

func (*EvilWallet) RequestFundsFromFaucet

func (e *EvilWallet) RequestFundsFromFaucet(options ...FaucetRequestOption) (initWallet *Wallet, err error)

RequestFundsFromFaucet requests funds from the faucet, then track the confirmed status of unspent output, also register the alias name for the unspent output if provided.

func (*EvilWallet) SetTxOutputsSolid

func (e *EvilWallet) SetTxOutputsSolid(outputs iotago.OutputIDs, clientID string)

SetTxOutputsSolid marks all outputs as solid in OutputManager for clientID.

func (*EvilWallet) UnspentOutputsLeft

func (e *EvilWallet) UnspentOutputsLeft(walletType WalletType) int

type FaucetRequestOption

type FaucetRequestOption func(*FaucetRequestOptions)

FaucetRequestOption is an option for faucet request.

func WithOutputAlias

func WithOutputAlias(aliasName string) FaucetRequestOption

WithOutputAlias returns an Option that is used to provide the Output of the Transaction.

type FaucetRequestOptions

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

FaucetRequestOptions is options for faucet request.

func NewFaucetRequestOptions

func NewFaucetRequestOptions(options ...FaucetRequestOption) *FaucetRequestOptions

NewFaucetRequestOptions creates options for a faucet request.

type Option

type Option func(*Options)

Option is the type that is used for options that can be passed into the CreateBlock method to configure its behavior.

func WithInputWallet

func WithInputWallet(issuer *Wallet) Option

WithInputWallet returns a BlockOption that is used to define the inputWallet of the Block.

func WithInputs

func WithInputs(inputs interface{}) Option

WithInputs returns an Option that is used to provide the Inputs of the Transaction.

func WithIssuanceStrategy

func WithIssuanceStrategy(strategy models.AllotmentStrategy, issuerID iotago.AccountID) Option

func WithIssuingTime

func WithIssuingTime(issuingTime time.Time) Option

WithIssuingTime returns a BlockOption that is used to set issuing time of the Block.

func WithOutputBatchAliases

func WithOutputBatchAliases(outputAliases map[string]types.Empty) Option

WithOutputBatchAliases returns a BlockOption that is used to determine which outputs should be added to the outWallet.

func WithOutputWallet

func WithOutputWallet(wallet *Wallet) Option

WithOutputWallet returns a BlockOption that is used to define the inputWallet of the Block.

func WithOutputs

func WithOutputs(outputsOptions []*OutputOption) Option

WithOutputs returns an Option that is used to define a non-colored Outputs for the Transaction in the Block.

func WithReuseOutputs

func WithReuseOutputs() Option

WithReuseOutputs returns a BlockOption that is used to enable deep spamming with Reuse wallet outputs.

type Options

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

Options is a struct that represents a collection of options that can be set when creating a block.

func NewOptions

func NewOptions(options ...Option) (option *Options, err error)

NewOptions is the constructor for the tx creation.

type OutputManager

type OutputManager struct {
	syncutils.RWMutex
	// contains filtered or unexported fields
}

OutputManager keeps track of the output statuses.

func NewOutputManager

func NewOutputManager(connector models.Connector, wallets *Wallets, log *logger.Logger) *OutputManager

NewOutputManager creates an OutputManager instance.

func (*OutputManager) AddOutput

func (o *OutputManager) AddOutput(w *Wallet, output *models.Output) *models.Output

AddOutput adds existing output from wallet w to the OutputManager.

func (*OutputManager) AwaitOutputToBeAccepted

func (o *OutputManager) AwaitOutputToBeAccepted(outputID iotago.OutputID, waitFor time.Duration) (accepted bool)

AwaitOutputToBeAccepted awaits for output from a provided outputID is accepted. Timeout is waitFor. Useful when we have only an address and no transactionID, e.g. faucet funds request.

func (*OutputManager) AwaitOutputToBeSolid

func (o *OutputManager) AwaitOutputToBeSolid(outID iotago.OutputID, clt models.Client, waitFor time.Duration) error

AwaitOutputToBeSolid awaits for solidification of a single output by provided clt.

func (*OutputManager) AwaitOutputsToBeSolid

func (o *OutputManager) AwaitOutputsToBeSolid(outputs iotago.OutputIDs, clt models.Client, maxGoroutines int) (allSolid bool)

AwaitOutputsToBeSolid awaits for all provided outputs are solid for a provided client.

func (*OutputManager) AwaitTransactionToBeAccepted

func (o *OutputManager) AwaitTransactionToBeAccepted(txID iotago.TransactionID, waitFor time.Duration) error

AwaitTransactionToBeAccepted awaits for acceptance of a single transaction.

func (*OutputManager) AwaitTransactionsConfirmation

func (o *OutputManager) AwaitTransactionsConfirmation(txIDs ...iotago.TransactionID)

AwaitTransactionsConfirmation awaits for transaction confirmation and updates wallet with outputIDs.

func (*OutputManager) AwaitWalletOutputsToBeConfirmed

func (o *OutputManager) AwaitWalletOutputsToBeConfirmed(wallet *Wallet)

AwaitWalletOutputsToBeConfirmed awaits for all outputs in the wallet are confirmed.

func (*OutputManager) GetOutput

func (o *OutputManager) GetOutput(outputID iotago.OutputID) (output *models.Output)

GetOutput returns the Output of the given outputID. Firstly checks if output can be retrieved by outputManager from wallet, if not does an API call.

func (*OutputManager) IssuerSolidOutIDMap

func (o *OutputManager) IssuerSolidOutIDMap(issuer string, outputID iotago.OutputID) (isSolid bool)

IssuerSolidOutIDMap checks whether output was marked as solid for a given node.

func (*OutputManager) OutputIDAddrMap

func (o *OutputManager) OutputIDAddrMap(outputID string) (addr string)

OutputIDAddrMap returns address corresponding to the outputID stored in OutputManager.

func (*OutputManager) OutputIDWalletMap

func (o *OutputManager) OutputIDWalletMap(outputID string) *Wallet

OutputIDWalletMap returns wallet corresponding to the outputID stored in OutputManager.

func (*OutputManager) RequestOutputsByTxID

func (o *OutputManager) RequestOutputsByTxID(txID iotago.TransactionID) (outputIDs iotago.OutputIDs)

RequestOutputsByTxID adds the outputs of a given transaction to the output status map.

func (*OutputManager) SetOutputIDSolidForIssuer

func (o *OutputManager) SetOutputIDSolidForIssuer(outputID iotago.OutputID, issuer string)

SetOutputIDSolidForIssuer sets solid flag for the provided outputID and issuer.

func (*OutputManager) Track

func (o *OutputManager) Track(outputIDs ...iotago.OutputID) (allConfirmed bool)

Track the confirmed statuses of the given outputIDs, it returns true if all of them are confirmed.

type OutputOption

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

type ScenarioAlias

type ScenarioAlias struct {
	Inputs  []string
	Outputs []string
}

func NewScenarioAlias

func NewScenarioAlias() ScenarioAlias

type ScenarioOption

type ScenarioOption func(scenario *EvilScenario)

func WithCreateAccounts

func WithCreateAccounts() ScenarioOption

func WithScenarioCustomConflicts

func WithScenarioCustomConflicts(batch EvilBatch) ScenarioOption

WithScenarioCustomConflicts specifies the EvilBatch that describes the UTXO structure that should be used for the spam.

func WithScenarioDeepSpamEnabled

func WithScenarioDeepSpamEnabled() ScenarioOption

WithScenarioDeepSpamEnabled enables deep spam, the outputs from available Reuse wallets or RestrictedReuse wallet if provided with WithReuseInputWalletForDeepSpam option will be used for spam instead fresh faucet outputs.

func WithScenarioInputWalletForDeepSpam

func WithScenarioInputWalletForDeepSpam(wallet *Wallet) ScenarioOption

WithScenarioInputWalletForDeepSpam reuse set to true, outputs from this wallet will be used for deep spamming, allows for controllable building of UTXO deep structures. Accepts only RestrictedReuse wallet type.

func WithScenarioReuseOutputWallet

func WithScenarioReuseOutputWallet(wallet *Wallet) ScenarioOption

WithScenarioReuseOutputWallet the outputs from the spam will be saved into this wallet, accepted types of wallet: Reuse, RestrictedReuse.

type Wallet

type Wallet struct {
	ID walletID

	*syncutils.RWMutex
	// contains filtered or unexported fields
}

Wallet is the definition of a wallet.

func NewWallet

func NewWallet(wType ...WalletType) *Wallet

NewWallet creates a wallet of a given type.

func (*Wallet) AddReuseAddress

func (w *Wallet) AddReuseAddress(addr string)

AddReuseAddress adds address to the reuse ready outputs' addresses pool for a Reuse wallet.

func (*Wallet) AddUnspentOutput

func (w *Wallet) AddUnspentOutput(output *models.Output)

AddUnspentOutput adds an unspentOutput of a given wallet.

func (*Wallet) AddrIndexMap

func (w *Wallet) AddrIndexMap(address string) uint64

AddrIndexMap returns the index for the address specified.

func (*Wallet) Address

func (w *Wallet) Address() *iotago.Ed25519Address

Address returns a new and unused address of a given wallet.

func (*Wallet) AddressOnIndex

func (w *Wallet) AddressOnIndex(index uint64) *iotago.Ed25519Address

AddressOnIndex returns a new and unused address of a given wallet.

func (*Wallet) AddressSigner

func (w *Wallet) AddressSigner(addr *iotago.Ed25519Address) iotago.AddressSigner

Sign signs the tx essence.

func (*Wallet) GetReuseAddress

func (w *Wallet) GetReuseAddress() string

GetReuseAddress get random address from reuse addresses reuseOutputsAddresses pool. Address is removed from the pool after selecting.

func (*Wallet) GetUnspentOutput

func (w *Wallet) GetUnspentOutput() *models.Output

GetUnspentOutput returns an unspent output on the oldest address ordered by index.

func (*Wallet) IndexAddrMap

func (w *Wallet) IndexAddrMap(outIndex uint64) string

IndexAddrMap returns the address for the index specified.

func (*Wallet) IsEmpty

func (w *Wallet) IsEmpty() (empty bool)

IsEmpty returns true if the wallet is empty.

func (*Wallet) KeyPair

func (w *Wallet) KeyPair(index uint64) (ed25519.PrivateKey, ed25519.PublicKey)

func (*Wallet) Type

func (w *Wallet) Type() WalletType

Type returns the wallet type.

func (*Wallet) UnspentOutput

func (w *Wallet) UnspentOutput(addr string) *models.Output

UnspentOutput returns the unspent output on the address.

func (*Wallet) UnspentOutputBalance

func (w *Wallet) UnspentOutputBalance(addr string) iotago.BaseToken

UnspentOutputBalance returns the balance on the unspent output sitting on the address specified.

func (*Wallet) UnspentOutputs

func (w *Wallet) UnspentOutputs() (outputs map[string]*models.Output)

UnspentOutputs returns all unspent outputs on the wallet.

func (*Wallet) UnspentOutputsLeft

func (w *Wallet) UnspentOutputsLeft() (left int)

UnspentOutputsLeft returns how many unused outputs are available in wallet.

func (*Wallet) UnspentOutputsLength

func (w *Wallet) UnspentOutputsLength() int

UnspentOutputsLength returns the number of unspent outputs on the wallet.

type WalletStatus

type WalletStatus int8

type WalletType

type WalletType int8

WalletType is the type of the wallet.

const (
	Other WalletType = iota
	// Fresh is used for automatic Faucet Requests, outputs are returned one by one.
	Fresh
	// Reuse stores resulting outputs of double spends or transactions issued by the evilWallet,
	// outputs from this wallet are reused in spamming scenario with flag reuse set to true and no RestrictedReuse wallet provided.
	// Reusing spammed outputs allows for creation of deeper UTXO DAG structure.
	Reuse
	// RestrictedReuse it is a reuse wallet, that will be available only to spamming scenarios that
	// will provide RestrictedWallet for the reuse spamming.
	RestrictedReuse
)

type Wallets

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

Wallets is a container of wallets.

func NewWallets

func NewWallets() *Wallets

NewWallets creates and returns a new Wallets container.

func (*Wallets) GetNextWallet

func (w *Wallets) GetNextWallet(walletType WalletType, minOutputsLeft int) (*Wallet, error)

GetNextWallet get next non-empty wallet based on provided type.

func (*Wallets) GetUnspentOutput

func (w *Wallets) GetUnspentOutput(wallet *Wallet) *models.Output

GetUnspentOutput gets first found unspent output for a given walletType.

func (*Wallets) GetWallet

func (w *Wallets) GetWallet(walletID walletID) *Wallet

GetWallet returns the wallet with the specified ID.

func (*Wallets) IsFaucetWalletAvailable

func (w *Wallets) IsFaucetWalletAvailable() bool

IsFaucetWalletAvailable checks if there is any faucet wallet left.

func (*Wallets) NewWallet

func (w *Wallets) NewWallet(walletType WalletType) *Wallet

NewWallet adds a new wallet to Wallets and returns the created wallet.

func (*Wallets) SetWalletReady

func (w *Wallets) SetWalletReady(wallet *Wallet)

SetWalletReady makes wallet ready to use, Fresh wallet is added to freshWallets queue.

func (*Wallets) UnspentOutputsLeft

func (w *Wallets) UnspentOutputsLeft(walletType WalletType) int

Jump to

Keyboard shortcuts

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