evilwallet

package
v0.1.0-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const EndSplitNumber = 126

EndSplitNumber defines the second split during funds creation for a big wallet, it can be large as funds are not splitted further, and it will not increase the congestion. So the big wallet size is FaucetSplitNumber * EndSplitNumber.

View Source
const (
	MinOutputStorageDeposit = iotago.BaseToken(500)
)

Variables

View Source
var (
	NoFreshOutputsAvailable = ierrors.New("no fresh wallet is available")
)

Functions

func AllScenariosListed

func AllScenariosListed() string

func IsScenarioAllowed

func IsScenarioAllowed(scenarioName string) bool

IsScenarioAllowed checks if a scenario is available.

func WithAccountsManager

func WithAccountsManager(manager *walletmanager.Manager) options.Option[EvilWallet]

func WithClients

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

func WithFaucetClient

func WithFaucetClient(url string) options.Option[EvilWallet]

func WithFaucetSplitNumber

func WithFaucetSplitNumber(n int) 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.OutputData, aliasName string)

AddInputAlias adds an input alias.

func (*AliasManager) AddInputAliases

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

AddInputAliases batch adds the inputs their respective aliases.

func (*AliasManager) AddOutputAlias

func (a *AliasManager) AddOutputAlias(output *models.OutputData, 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.OutputData, 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.OutputData, bool)

GetInput returns the input for the alias specified.

func (*AliasManager) GetOutput

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

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
}

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 {
	log.Logger
	// contains filtered or unexported fields
}

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

func NewEvilWallet

func NewEvilWallet(logger log.Logger, 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) ClearWalletData

func (e *EvilWallet) ClearWalletData(wallet *Wallet)

func (*EvilWallet) Connector

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

Connector give access to the EvilWallet connector.

func (*EvilWallet) CreateBlock

func (e *EvilWallet) CreateBlock(ctx context.Context, clt models.Client, payload iotago.Payload, issuer wallet.Account, strongParents ...iotago.BlockID) (*iotago.Block, error)

CreateBlock creates a block with the update wallet with newly created output freshly requested Congestion and Issuance data.

func (*EvilWallet) CreateTransaction

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

CreateTransaction creates a transaction builder based on provided options. If no input wallet is provided, the next non-empty faucet wallet is used. No mana allotment is done here, tx is not signed and built yet. Inputs of the transaction are determined in three ways: 1 - inputs are provided directly without associated alias, 2- provided only an alias, but inputs are stored in an alias manager, 3 - provided alias, but there are no inputs assigned in Alias manager, so aliases will be assigned to next ready inputs from input wallet.

func (*EvilWallet) GetAccount

func (e *EvilWallet) GetAccount(ctx context.Context, alias string) (wallet.Account, error)

func (*EvilWallet) GetClients

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

GetClients returns the given number of clients.

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(ctx context.Context, scenario *EvilScenario) (*models.PayloadIssuanceData, ScenarioAlias, error)

func (*EvilWallet) PrepareAndPostBlockWithPayload

func (e *EvilWallet) PrepareAndPostBlockWithPayload(ctx context.Context, clt models.Client, payload iotago.Payload, issuer wallet.Account) (iotago.BlockID, error)

func (*EvilWallet) PrepareAndPostBlockWithTxBuildData

func (e *EvilWallet) PrepareAndPostBlockWithTxBuildData(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account) (iotago.BlockID, *iotago.Transaction, error)

func (*EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait

func (e *EvilWallet) PrepareAndPostBlockWithTxBuildDataAwait(ctx context.Context, clt models.Client, txBuilder *builder.TransactionBuilder, issuer wallet.Account) (iotago.BlockID, error)

func (*EvilWallet) PrepareCustomConflicts

func (e *EvilWallet) PrepareCustomConflicts(ctx context.Context, conflicts ConflictSlice) (conflictBatch []*models.PayloadIssuanceData, err error)

func (*EvilWallet) PrepareCustomConflictsSpam

func (e *EvilWallet) PrepareCustomConflictsSpam(scenario *EvilScenario) ([]ConflictSlice, ScenarioAlias)

func (*EvilWallet) RemoveClient

func (e *EvilWallet) RemoveClient(clientURL string)

func (*EvilWallet) RequestFreshBigFaucetWallet

func (e *EvilWallet) RequestFreshBigFaucetWallet(ctx context.Context) error

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

func (*EvilWallet) RequestFreshFaucetWallet

func (e *EvilWallet) RequestFreshFaucetWallet(ctx context.Context) 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(ctx context.Context) (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) SplitOutputsInParallel

func (e *EvilWallet) SplitOutputsInParallel(ctx context.Context, inputWallet, outputWallet *Wallet) error

SplitOutputsInParallel splits all outputs from the provided input wallet in parallel, txs are created in a massive bulks, it is faster but gives a huge overhead for the network, outputs are saved to the outputWallet.

func (*EvilWallet) SplitOutputsSequentially

func (e *EvilWallet) SplitOutputsSequentially(ctx context.Context, inputWallet, outputWallet *Wallet) error

SplitOutputsSequentially splits all outputs from the provided input wallet sequentially, txs are created one by one, it is slower but gives less overhead for the network, outputs are saved to the outputWallet.

func (*EvilWallet) UnspentOutputsLeft

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

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 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 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 {
	log.Logger

	syncutils.RWMutex
	// contains filtered or unexported fields
}

OutputManager keeps track of the output statuses.

func NewOutputManager

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

NewOutputManager creates an OutputManager instance. All outputs are mapped based on their address, so address should never be reused.

func (*OutputManager) AddOutput

func (o *OutputManager) AddOutput(api iotago.API, w *Wallet, output iotago.Output) *models.OutputData

AddOutput adds existing output from wallet w to the OutputManager.

func (*OutputManager) AwaitTransactionsAcceptance

func (o *OutputManager) AwaitTransactionsAcceptance(ctx context.Context, txIDs ...iotago.TransactionID)

AwaitTransactionsAcceptance awaits for transaction confirmation and updates wallet with outputIDs.

func (*OutputManager) AwaitWalletOutputsToBeConfirmed

func (o *OutputManager) AwaitWalletOutputsToBeConfirmed(ctx context.Context, wallet *Wallet)

AwaitWalletOutputsToBeConfirmed awaits for all outputs in the wallet are confirmed.

func (*OutputManager) ClearTempIDs

func (o *OutputManager) ClearTempIDs(id ...models.TempOutputID)

func (*OutputManager) GetOutput

func (o *OutputManager) GetOutput(ctx context.Context, id models.TempOutputID, outputID iotago.OutputID) (output *models.OutputData)

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

func (*OutputManager) TempIDWalletMap

func (o *OutputManager) TempIDWalletMap(outputID models.TempOutputID) *Wallet

TempIDWalletMap returns wallet corresponding to the address stored in OutputManager.

func (*OutputManager) Track

func (o *OutputManager) Track(ctx context.Context, 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(id models.TempOutputID)

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

func (*Wallet) AddUnspentOutput

func (w *Wallet) AddUnspentOutput(id models.TempOutputID, output *models.OutputData)

AddUnspentOutput adds an unspentOutput of a given wallet.

func (*Wallet) AddrIndexMap

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

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 uint32) *iotago.Ed25519Address

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

func (*Wallet) Clear

func (w *Wallet) Clear()

func (*Wallet) GetReuseAddress

func (w *Wallet) GetReuseAddress() models.TempOutputID

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.OutputData

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

func (*Wallet) IndexTempIDMap

func (w *Wallet) IndexTempIDMap(outIndex uint32) models.TempOutputID

IndexTempIDMap 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 uint32) (ed25519.PrivateKey, ed25519.PublicKey)

func (*Wallet) Type

func (w *Wallet) Type() WalletType

Type returns the wallet type.

func (*Wallet) UnspentOutput

func (w *Wallet) UnspentOutput(id models.TempOutputID) *models.OutputData

UnspentOutput returns the unspent output on the address.

func (*Wallet) UnspentOutputBalance

func (w *Wallet) UnspentOutputBalance(id models.TempOutputID) iotago.BaseToken

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

func (*Wallet) UnspentOutputs

func (w *Wallet) UnspentOutputs() (outputs map[models.TempOutputID]*models.OutputData)

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) GetWallet

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

GetWallet returns the wallet with the specified ID.

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