cooked-validators
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cooked.Attack.DatumHijacking

Description

This module provides an automated attack to try and redirect outputs to a certain target with a similar datum type.

Synopsis

Documentation

redirectOutputTweakAny :: forall owner owner' m. (MonadTweak m, OwnerConstraints owner, OwnerConstraints owner') => (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script) -> Maybe owner') -> (Integer -> Bool) -> m (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script)) Source #

A version of redirectOutputTweakAll where, instead of modifying all the outputs targeted by the input predicates in the same transaction, we modify one of them at a time, relying on the MonadPlus instance of m.

datumHijackingAttackAny Source #

Arguments

:: forall owner owner' m. (MonadTweak m, OwnerConstraints owner, OwnerConstraints owner') 
=> (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script) -> Bool)

Predicate to select outputs to steal, depending on the intended recipient, the datum, and the value.

-> (Integer -> Bool)

The selection predicate may match more than one output. Use this predicate to restrict to the i-th of the outputs (counting from the left, starting at zero) chosen by the selection predicate with this predicate.

-> owner'

The thief

-> m (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script)) 

A version of datumHijackingAttackAll relying on the rules of redirectOutputTweakAny.

datumHijackingAttack :: forall owner owner' m. (MonadTweak m, OwnerConstraints owner, OwnerConstraints owner') => owner' -> m (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script)) Source #

The default datum hijacking attack. It tries to redirect any output for which the owner is of type owner and branches at each attempt.

redirectOutputTweakAll Source #

Arguments

:: forall owner owner' m. (MonadTweak m, OwnerConstraints owner, OwnerConstraints owner') 
=> (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script) -> Maybe owner')

Return Just the new owner, or Nothing if you want to leave this output unchanged.

-> (Integer -> Bool)

The redirection described by the previous argument might apply to more than one of the outputs of the transaction. Use this predicate to select which of the redirectable outputs to actually redirect. We count the redirectable outputs from the left to the right, starting with zero.

-> m [ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script)] 

Redirects some outputs from one owner to another owner, which can be of different types. Returns the list of outputs it redirected (as they were before the modification), in the order in which they occurred on the original transaction.

datumHijackingAttackAll Source #

Arguments

:: forall owner owner' m. (MonadTweak m, OwnerConstraints owner, OwnerConstraints owner') 
=> (ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script) -> Bool)

Predicate to select outputs to steal, depending on the intended recipient, the datum, and the value.

-> (Integer -> Bool)

The selection predicate may match more than one output. Use this predicate to restrict to the i-th of the outputs (counting from the left, starting at zero) chosen by the selection predicate with this predicate.

-> owner'

The thief

-> m [ConcreteOutput owner TxSkelOutDatum TxSkelOutValue (Versioned Script)] 

A datum hijacking attack, simplified: This attack tries to substitute a different recipient on outputs belonging to scripts, but leaves the datum as it is. That is, it tests for careless uses of something like txInfoOutputs in places where something like getContinuingOutputs should be used. If this attack goes through, however, a "proper" datum hijacking attack that modifies the datum in a way that (the relevant part of) the toBuiltinData-translation stays the same will also work.

A DatumHijackingLbl with the hash of the "thief" validator is added to the labels of the TxSkel using addLabelTweak.

This attack returns the list of outputs it redirected, in the order in which they occurred on the original transaction. If no output is redirected, this attack fails.