reentryattack

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: BlueOak-1.0.0 Imports: 9 Imported by: 0

README

Reentry Contract Creation

Have solc and abigen installed on your system and run from this directory:

solc --combined-json abi,bin --optimize --overwrite ReentryAttack.sol -o .
abigen --combined-json combined.json --pkg reentryattack --out ./contract.go
rm combined.json

Reentry Contract Usage

In order to see the effects of a reentry attack on a vulnerable contract, VulnerableToReentryAttack.sol can be used.

NOTE: The contract interface is no longer compatible with the dex/networks/eth/contracts/v0 API, so the following substitution of the ETHSwapV0 bytecode with the vulnerable contract's code will not work without updating the vulnerable "ETHSwap" contract.

solc --combined-json abi,bin --optimize --overwrite VulnerableToReentryAttack.sol -o .
abigen --combined-json combined.json --pkg v0 --out ../../../dex/networks/eth/contracts/v0/contract.go
rm combined.json

Then, the contract's hex in the newly created contract.go file must be used in the harness, which deploys the contract used for testing, by replacing the hex there and restarting the harness.

Finally, the harness tests in client/asset/eth contains a test that should fail and show that indeed funds can be siphoned from the vulnerable contract.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EthswapABI = EthswapMetaData.ABI

EthswapABI is the input ABI used to generate the binding from. Deprecated: Use EthswapMetaData.ABI instead.

View Source
var EthswapMetaData = &bind.MetaData{
	ABI: "[{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"refundTimestamp\",\"type\":\"uint256\"},{\"internalType\":\"bytes32\",\"name\":\"secretHash\",\"type\":\"bytes32\"},{\"internalType\":\"address\",\"name\":\"participant\",\"type\":\"address\"}],\"name\":\"initiate\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes32\",\"name\":\"secretHash\",\"type\":\"bytes32\"}],\"name\":\"refund\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]",
}

EthswapMetaData contains all meta data concerning the Ethswap contract.

View Source
var ReentryAttackABI = ReentryAttackMetaData.ABI

ReentryAttackABI is the input ABI used to generate the binding from. Deprecated: Use ReentryAttackMetaData.ABI instead.

View Source
var ReentryAttackBin = ReentryAttackMetaData.Bin

ReentryAttackBin is the compiled bytecode used for deploying new contracts. Deprecated: Use ReentryAttackMetaData.Bin instead.

View Source
var ReentryAttackMetaData = &bind.MetaData{
	ABI: "[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"stateMutability\":\"payable\",\"type\":\"fallback\"},{\"inputs\":[],\"name\":\"allYourBase\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"areBelongToUs\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"owner\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"es\",\"type\":\"address\"},{\"internalType\":\"bytes32\",\"name\":\"sh\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"refundTimestamp\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"participant\",\"type\":\"address\"}],\"name\":\"setUsUpTheBomb\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"}]",
	Bin: "0x608060405234801561001057600080fd5b50600080546001600160a01b0319163317905561029b806100326000396000f3fe60806040526004361061003f5760003560e01c8063627599ee146100595780638da5cb5b1461006e5780638f110770146100aa578063b9ce28a4146100bf575b674563918244f40000471015610057576100576100d2565b005b34801561006557600080fd5b5061005761013b565b34801561007a57600080fd5b5060005461008e906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b3480156100b657600080fd5b506100576100d2565b6100576100cd36600461021f565b610178565b600254600154604051633924fddb60e11b81526001600160a01b0390921691637249fbb6916101079160040190815260200190565b600060405180830381600087803b15801561012157600080fd5b505af1158015610135573d6000803e3d6000fd5b50505050565b600080546040516001600160a01b03909116914780156108fc02929091818181858888f19350505050158015610175573d6000803e3d6000fd5b50565b600280546001600160a01b0319166001600160a01b03868116918217909255600185905560405163ae05214760e01b8152600481018590526024810186905291831660448301529063ae0521479034906064016000604051808303818588803b1580156101e457600080fd5b505af11580156101f8573d6000803e3d6000fd5b505050505050505050565b80356001600160a01b038116811461021a57600080fd5b919050565b6000806000806080858703121561023557600080fd5b61023e85610203565b9350602085013592506040850135915061025a60608601610203565b90509295919450925056fea2646970667358221220eaf6de1ca5654a3578dcda1ff161624f98e48b3da704bfd4621c51798f4a800d64736f6c634300080f0033",
}

ReentryAttackMetaData contains all meta data concerning the ReentryAttack contract.

Functions

This section is empty.

Types

type Ethswap

type Ethswap struct {
	EthswapCaller     // Read-only binding to the contract
	EthswapTransactor // Write-only binding to the contract
	EthswapFilterer   // Log filterer for contract events
}

Ethswap is an auto generated Go binding around an Ethereum contract.

func NewEthswap

func NewEthswap(address common.Address, backend bind.ContractBackend) (*Ethswap, error)

NewEthswap creates a new instance of Ethswap, bound to a specific deployed contract.

type EthswapCaller

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

EthswapCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewEthswapCaller

func NewEthswapCaller(address common.Address, caller bind.ContractCaller) (*EthswapCaller, error)

NewEthswapCaller creates a new read-only instance of Ethswap, bound to a specific deployed contract.

type EthswapCallerRaw

type EthswapCallerRaw struct {
	Contract *EthswapCaller // Generic read-only contract binding to access the raw methods on
}

EthswapCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*EthswapCallerRaw) Call

func (_Ethswap *EthswapCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type EthswapCallerSession

type EthswapCallerSession struct {
	Contract *EthswapCaller // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts  // Call options to use throughout this session
}

EthswapCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

type EthswapFilterer

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

EthswapFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewEthswapFilterer

func NewEthswapFilterer(address common.Address, filterer bind.ContractFilterer) (*EthswapFilterer, error)

NewEthswapFilterer creates a new log filterer instance of Ethswap, bound to a specific deployed contract.

type EthswapRaw

type EthswapRaw struct {
	Contract *Ethswap // Generic contract binding to access the raw methods on
}

EthswapRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*EthswapRaw) Call

func (_Ethswap *EthswapRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*EthswapRaw) Transact

func (_Ethswap *EthswapRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*EthswapRaw) Transfer

func (_Ethswap *EthswapRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type EthswapSession

type EthswapSession struct {
	Contract     *Ethswap          // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

EthswapSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*EthswapSession) Initiate

func (_Ethswap *EthswapSession) Initiate(refundTimestamp *big.Int, secretHash [32]byte, participant common.Address) (*types.Transaction, error)

Initiate is a paid mutator transaction binding the contract method 0xae052147.

Solidity: function initiate(uint256 refundTimestamp, bytes32 secretHash, address participant) payable returns()

func (*EthswapSession) Refund

func (_Ethswap *EthswapSession) Refund(secretHash [32]byte) (*types.Transaction, error)

Refund is a paid mutator transaction binding the contract method 0x7249fbb6.

Solidity: function refund(bytes32 secretHash) returns()

type EthswapTransactor

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

EthswapTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewEthswapTransactor

func NewEthswapTransactor(address common.Address, transactor bind.ContractTransactor) (*EthswapTransactor, error)

NewEthswapTransactor creates a new write-only instance of Ethswap, bound to a specific deployed contract.

func (*EthswapTransactor) Initiate

func (_Ethswap *EthswapTransactor) Initiate(opts *bind.TransactOpts, refundTimestamp *big.Int, secretHash [32]byte, participant common.Address) (*types.Transaction, error)

Initiate is a paid mutator transaction binding the contract method 0xae052147.

Solidity: function initiate(uint256 refundTimestamp, bytes32 secretHash, address participant) payable returns()

func (*EthswapTransactor) Refund

func (_Ethswap *EthswapTransactor) Refund(opts *bind.TransactOpts, secretHash [32]byte) (*types.Transaction, error)

Refund is a paid mutator transaction binding the contract method 0x7249fbb6.

Solidity: function refund(bytes32 secretHash) returns()

type EthswapTransactorRaw

type EthswapTransactorRaw struct {
	Contract *EthswapTransactor // Generic write-only contract binding to access the raw methods on
}

EthswapTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*EthswapTransactorRaw) Transact

func (_Ethswap *EthswapTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*EthswapTransactorRaw) Transfer

func (_Ethswap *EthswapTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type EthswapTransactorSession

type EthswapTransactorSession struct {
	Contract     *EthswapTransactor // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts  // Transaction auth options to use throughout this session
}

EthswapTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

func (*EthswapTransactorSession) Initiate

func (_Ethswap *EthswapTransactorSession) Initiate(refundTimestamp *big.Int, secretHash [32]byte, participant common.Address) (*types.Transaction, error)

Initiate is a paid mutator transaction binding the contract method 0xae052147.

Solidity: function initiate(uint256 refundTimestamp, bytes32 secretHash, address participant) payable returns()

func (*EthswapTransactorSession) Refund

func (_Ethswap *EthswapTransactorSession) Refund(secretHash [32]byte) (*types.Transaction, error)

Refund is a paid mutator transaction binding the contract method 0x7249fbb6.

Solidity: function refund(bytes32 secretHash) returns()

type ReentryAttack

type ReentryAttack struct {
	ReentryAttackCaller     // Read-only binding to the contract
	ReentryAttackTransactor // Write-only binding to the contract
	ReentryAttackFilterer   // Log filterer for contract events
}

ReentryAttack is an auto generated Go binding around an Ethereum contract.

func DeployReentryAttack

func DeployReentryAttack(auth *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, *ReentryAttack, error)

DeployReentryAttack deploys a new Ethereum contract, binding an instance of ReentryAttack to it.

func NewReentryAttack

func NewReentryAttack(address common.Address, backend bind.ContractBackend) (*ReentryAttack, error)

NewReentryAttack creates a new instance of ReentryAttack, bound to a specific deployed contract.

type ReentryAttackCaller

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

ReentryAttackCaller is an auto generated read-only Go binding around an Ethereum contract.

func NewReentryAttackCaller

func NewReentryAttackCaller(address common.Address, caller bind.ContractCaller) (*ReentryAttackCaller, error)

NewReentryAttackCaller creates a new read-only instance of ReentryAttack, bound to a specific deployed contract.

func (*ReentryAttackCaller) Owner

func (_ReentryAttack *ReentryAttackCaller) Owner(opts *bind.CallOpts) (common.Address, error)

Owner is a free data retrieval call binding the contract method 0x8da5cb5b.

Solidity: function owner() view returns(address)

type ReentryAttackCallerRaw

type ReentryAttackCallerRaw struct {
	Contract *ReentryAttackCaller // Generic read-only contract binding to access the raw methods on
}

ReentryAttackCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.

func (*ReentryAttackCallerRaw) Call

func (_ReentryAttack *ReentryAttackCallerRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

type ReentryAttackCallerSession

type ReentryAttackCallerSession struct {
	Contract *ReentryAttackCaller // Generic contract caller binding to set the session for
	CallOpts bind.CallOpts        // Call options to use throughout this session
}

ReentryAttackCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.

func (*ReentryAttackCallerSession) Owner

func (_ReentryAttack *ReentryAttackCallerSession) Owner() (common.Address, error)

Owner is a free data retrieval call binding the contract method 0x8da5cb5b.

Solidity: function owner() view returns(address)

type ReentryAttackFilterer

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

ReentryAttackFilterer is an auto generated log filtering Go binding around an Ethereum contract events.

func NewReentryAttackFilterer

func NewReentryAttackFilterer(address common.Address, filterer bind.ContractFilterer) (*ReentryAttackFilterer, error)

NewReentryAttackFilterer creates a new log filterer instance of ReentryAttack, bound to a specific deployed contract.

type ReentryAttackRaw

type ReentryAttackRaw struct {
	Contract *ReentryAttack // Generic contract binding to access the raw methods on
}

ReentryAttackRaw is an auto generated low-level Go binding around an Ethereum contract.

func (*ReentryAttackRaw) Call

func (_ReentryAttack *ReentryAttackRaw) Call(opts *bind.CallOpts, result *[]interface{}, method string, params ...interface{}) error

Call invokes the (constant) contract method with params as input values and sets the output to result. The result type might be a single field for simple returns, a slice of interfaces for anonymous returns and a struct for named returns.

func (*ReentryAttackRaw) Transact

func (_ReentryAttack *ReentryAttackRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*ReentryAttackRaw) Transfer

func (_ReentryAttack *ReentryAttackRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type ReentryAttackSession

type ReentryAttackSession struct {
	Contract     *ReentryAttack    // Generic contract binding to set the session for
	CallOpts     bind.CallOpts     // Call options to use throughout this session
	TransactOpts bind.TransactOpts // Transaction auth options to use throughout this session
}

ReentryAttackSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.

func (*ReentryAttackSession) AllYourBase

func (_ReentryAttack *ReentryAttackSession) AllYourBase() (*types.Transaction, error)

AllYourBase is a paid mutator transaction binding the contract method 0x8f110770.

Solidity: function allYourBase() returns()

func (*ReentryAttackSession) AreBelongToUs

func (_ReentryAttack *ReentryAttackSession) AreBelongToUs() (*types.Transaction, error)

AreBelongToUs is a paid mutator transaction binding the contract method 0x627599ee.

Solidity: function areBelongToUs() returns()

func (*ReentryAttackSession) Fallback

func (_ReentryAttack *ReentryAttackSession) Fallback(calldata []byte) (*types.Transaction, error)

Fallback is a paid mutator transaction binding the contract fallback function.

Solidity: fallback() payable returns()

func (*ReentryAttackSession) Owner

func (_ReentryAttack *ReentryAttackSession) Owner() (common.Address, error)

Owner is a free data retrieval call binding the contract method 0x8da5cb5b.

Solidity: function owner() view returns(address)

func (*ReentryAttackSession) SetUsUpTheBomb

func (_ReentryAttack *ReentryAttackSession) SetUsUpTheBomb(es common.Address, sh [32]byte, refundTimestamp *big.Int, participant common.Address) (*types.Transaction, error)

SetUsUpTheBomb is a paid mutator transaction binding the contract method 0xb9ce28a4.

Solidity: function setUsUpTheBomb(address es, bytes32 sh, uint256 refundTimestamp, address participant) payable returns()

type ReentryAttackTransactor

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

ReentryAttackTransactor is an auto generated write-only Go binding around an Ethereum contract.

func NewReentryAttackTransactor

func NewReentryAttackTransactor(address common.Address, transactor bind.ContractTransactor) (*ReentryAttackTransactor, error)

NewReentryAttackTransactor creates a new write-only instance of ReentryAttack, bound to a specific deployed contract.

func (*ReentryAttackTransactor) AllYourBase

func (_ReentryAttack *ReentryAttackTransactor) AllYourBase(opts *bind.TransactOpts) (*types.Transaction, error)

AllYourBase is a paid mutator transaction binding the contract method 0x8f110770.

Solidity: function allYourBase() returns()

func (*ReentryAttackTransactor) AreBelongToUs

func (_ReentryAttack *ReentryAttackTransactor) AreBelongToUs(opts *bind.TransactOpts) (*types.Transaction, error)

AreBelongToUs is a paid mutator transaction binding the contract method 0x627599ee.

Solidity: function areBelongToUs() returns()

func (*ReentryAttackTransactor) Fallback

func (_ReentryAttack *ReentryAttackTransactor) Fallback(opts *bind.TransactOpts, calldata []byte) (*types.Transaction, error)

Fallback is a paid mutator transaction binding the contract fallback function.

Solidity: fallback() payable returns()

func (*ReentryAttackTransactor) SetUsUpTheBomb

func (_ReentryAttack *ReentryAttackTransactor) SetUsUpTheBomb(opts *bind.TransactOpts, es common.Address, sh [32]byte, refundTimestamp *big.Int, participant common.Address) (*types.Transaction, error)

SetUsUpTheBomb is a paid mutator transaction binding the contract method 0xb9ce28a4.

Solidity: function setUsUpTheBomb(address es, bytes32 sh, uint256 refundTimestamp, address participant) payable returns()

type ReentryAttackTransactorRaw

type ReentryAttackTransactorRaw struct {
	Contract *ReentryAttackTransactor // Generic write-only contract binding to access the raw methods on
}

ReentryAttackTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.

func (*ReentryAttackTransactorRaw) Transact

func (_ReentryAttack *ReentryAttackTransactorRaw) Transact(opts *bind.TransactOpts, method string, params ...interface{}) (*types.Transaction, error)

Transact invokes the (paid) contract method with params as input values.

func (*ReentryAttackTransactorRaw) Transfer

func (_ReentryAttack *ReentryAttackTransactorRaw) Transfer(opts *bind.TransactOpts) (*types.Transaction, error)

Transfer initiates a plain transaction to move funds to the contract, calling its default method if one is available.

type ReentryAttackTransactorSession

type ReentryAttackTransactorSession struct {
	Contract     *ReentryAttackTransactor // Generic contract transactor binding to set the session for
	TransactOpts bind.TransactOpts        // Transaction auth options to use throughout this session
}

ReentryAttackTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.

func (*ReentryAttackTransactorSession) AllYourBase

func (_ReentryAttack *ReentryAttackTransactorSession) AllYourBase() (*types.Transaction, error)

AllYourBase is a paid mutator transaction binding the contract method 0x8f110770.

Solidity: function allYourBase() returns()

func (*ReentryAttackTransactorSession) AreBelongToUs

func (_ReentryAttack *ReentryAttackTransactorSession) AreBelongToUs() (*types.Transaction, error)

AreBelongToUs is a paid mutator transaction binding the contract method 0x627599ee.

Solidity: function areBelongToUs() returns()

func (*ReentryAttackTransactorSession) Fallback

func (_ReentryAttack *ReentryAttackTransactorSession) Fallback(calldata []byte) (*types.Transaction, error)

Fallback is a paid mutator transaction binding the contract fallback function.

Solidity: fallback() payable returns()

func (*ReentryAttackTransactorSession) SetUsUpTheBomb

func (_ReentryAttack *ReentryAttackTransactorSession) SetUsUpTheBomb(es common.Address, sh [32]byte, refundTimestamp *big.Int, participant common.Address) (*types.Transaction, error)

SetUsUpTheBomb is a paid mutator transaction binding the contract method 0xb9ce28a4.

Solidity: function setUsUpTheBomb(address es, bytes32 sh, uint256 refundTimestamp, address participant) payable returns()

Jump to

Keyboard shortcuts

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