erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Log | Files | Refs

commit 830bb0952c72d277f0a743c0e4b40933b5e2dd29
parent 3645a1eb67e5555fc983f9a82fbc02fe319a5d55
Author: nolash <dev@holbrook.no>
Date:   Fri,  1 Jan 2021 20:24:21 +0100

Add tests for index iteration and insufficient approve

Diffstat:
Mpython/erc20_approval_escrow/data/TransferApproval.bin | 4++--
Mpython/erc20_approval_escrow/data/TransferApproval.json | 2+-
Mpython/tests/test_app.py | 38++++++++++++++++++++++++++++++++++++++
Msolidity/TransferApproval.bin | 4++--
Msolidity/TransferApproval.json | 2+-
Msolidity/TransferApproval.sol | 21++++++---------------
6 files changed, 50 insertions(+), 21 deletions(-)

diff --git a/python/erc20_approval_escrow/data/TransferApproval.bin b/python/erc20_approval_escrow/data/TransferApproval.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b5060405162001755380380620017558339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b6113d6806200037f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c80636e417c69116100665780636e417c691461015d5780637780c14f1461018d57806381d12c58146101ab578063b0addede146101df578063bac911ac1461020f5761009e565b806306661abd146100a357806308ae6377146100c15780630a144391146100df5780632d7788db1461010f57806357ec347a1461013f575b600080fd5b6100ab61023f565b6040516100b89190611163565b60405180910390f35b6100c9610245565b6040516100d69190611163565b60405180910390f35b6100f960048036038101906100f49190610f3b565b610270565b6040516101069190611108565b60405180910390f35b61012960048036038101906101249190610fb3565b610290565b6040516101369190611108565b60405180910390f35b610147610585565b6040516101549190611163565b60405180910390f35b61017760048036038101906101729190610fb3565b61059a565b6040516101849190611108565b60405180910390f35b6101956108c3565b6040516101a29190611163565b60405180910390f35b6101c560048036038101906101c09190610fb3565b6108c9565b6040516101d695949392919061117e565b60405180910390f35b6101f960048036038101906101f49190610f64565b61095f565b6040516102069190611163565b60405180910390f35b61022960048036038101906102249190610fb3565b610bf9565b6040516102369190611163565b60405180910390f35b60035481565b6000806002546001546102589190611221565b1415610267576000905061026d565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661031e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161031590611123565b60405180910390fd5b60008060008481526020019081526020016000209050600081600001541161037b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037290611143565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16856004015460405160240161041a939291906110d1565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516104a491906110ba565b6000604051808303816000865af19150503d80600081146104e1576040519150601f19603f3d011682016040523d82523d6000602084013e6104e6565b606091505b50915091506104f88360000154610d98565b811561053e577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040516105319190611163565b60405180910390a161057a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb83600001546040516105719190611163565b60405180910390a15b819350505050919050565b6000600180546105959190611221565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610628576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161061f90611123565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610685576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067c90611143565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401610724939291906110d1565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516107ae91906110ba565b6000604051808303816000865af19150503d80600081146107eb576040519150601f19603f3d011682016040523d82523d6000602084013e6107f0565b606091505b509150915081610829577f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b6108368360000154610d98565b811561087c577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd836000015460405161086f9190611163565b60405180910390a16108b8565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb83600001546040516108af9190611163565b60405180910390a15b819350505050919050565b60025481565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000610969610ea0565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610b3b906112fa565b919050555060016000815480929190610b53906112fa565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610be29291906111d1565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d8c5760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d785784831415610d695780600001519350505050610d93565b8280610d74906112fa565b9350505b508080610d84906112fa565b915050610c04565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610e45906112d0565b919050555060006003541115610e9357600254811415610e8e576000610e6b6000610bf9565b90506000811415610e8457600154600281905550610e8c565b806002819055505b505b610e9d565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610f2081611372565b92915050565b600081359050610f3581611389565b92915050565b600060208284031215610f4d57600080fd5b6000610f5b84828501610f11565b91505092915050565b600080600060608486031215610f7957600080fd5b6000610f8786828701610f11565b9350506020610f9886828701610f11565b9250506040610fa986828701610f26565b9150509250925092565b600060208284031215610fc557600080fd5b6000610fd384828501610f26565b91505092915050565b610fe581611255565b82525050565b610ff481611267565b82525050565b6000611005826111fa565b61100f8185611205565b935061101f81856020860161129d565b80840191505092915050565b6000611038600d83611210565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b6000611078601383611210565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110b481611293565b82525050565b60006110c68284610ffa565b915081905092915050565b60006060820190506110e66000830186610fdc565b6110f36020830185610fdc565b61110060408301846110ab565b949350505050565b600060208201905061111d6000830184610feb565b92915050565b6000602082019050818103600083015261113c8161102b565b9050919050565b6000602082019050818103600083015261115c8161106b565b9050919050565b600060208201905061117860008301846110ab565b92915050565b600060a08201905061119360008301886110ab565b6111a06020830187610fdc565b6111ad6040830186610fdc565b6111ba6060830185610fdc565b6111c760808301846110ab565b9695505050505050565b60006040820190506111e660008301856110ab565b6111f360208301846110ab565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b600061122c82611293565b915061123783611293565b92508282101561124a57611249611343565b5b828203905092915050565b600061126082611273565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156112bb5780820151818401526020810190506112a0565b838111156112ca576000848401525b50505050565b60006112db82611293565b915060008214156112ef576112ee611343565b5b600182039050919050565b600061130582611293565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561133857611337611343565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b61137b81611255565b811461138657600080fd5b50565b61139281611293565b811461139d57600080fd5b5056fea2646970667358221220d441a811b83873b5e6f885838296dc5de101a07165838838514de472d224d11f64736f6c63430008000033 -\ No newline at end of file +60806040523480156200001157600080fd5b50604051620016e1380380620016e18339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b611362806200037f6000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806357ec347a1161006657806357ec347a146101345780636e417c691461015257806381d12c5814610182578063b0addede146101b6578063bac911ac146101e657610093565b806306661abd1461009857806308ae6377146100b65780630a144391146100d45780632d7788db14610104575b600080fd5b6100a0610216565b6040516100ad91906110ef565b60405180910390f35b6100be61021c565b6040516100cb91906110ef565b60405180910390f35b6100ee60048036038101906100e99190610ec7565b610247565b6040516100fb9190611094565b60405180910390f35b61011e60048036038101906101199190610f3f565b610267565b60405161012b9190611094565b60405180910390f35b61013c610553565b60405161014991906110ef565b60405180910390f35b61016c60048036038101906101679190610f3f565b610568565b6040516101799190611094565b60405180910390f35b61019c60048036038101906101979190610f3f565b610855565b6040516101ad95949392919061110a565b60405180910390f35b6101d060048036038101906101cb9190610ef0565b6108eb565b6040516101dd91906110ef565b60405180910390f35b61020060048036038101906101fb9190610f3f565b610b85565b60405161020d91906110ef565b60405180910390f35b60035481565b60008060025460015461022f91906111ad565b141561023e5760009050610244565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166102f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ec906110af565b60405180910390fd5b6000806000848152602001908152602001600020905082816000015414610351576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610348906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016103f09392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161047a9190611046565b6000604051808303816000865af19150503d80600081146104b7576040519150601f19603f3d011682016040523d82523d6000602084013e6104bc565b606091505b50915091506104ce8360000154610d24565b8115610510577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161050391906110ef565b60405180910390a1610548565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161053f91906110ef565b60405180910390a15b819350505050919050565b60006001805461056391906111ad565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105ed906110af565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610653576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161064a906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016106f29392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161077c9190611046565b6000604051808303816000865af19150503d80600081146107b9576040519150601f19603f3d011682016040523d82523d6000602084013e6107be565b606091505b50915091506107d08360000154610d24565b8115610812577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161080591906110ef565b60405180910390a161084a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161084191906110ef565b60405180910390a15b819350505050919050565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b60006108f5610e2c565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610ac790611286565b919050555060016000815480929190610adf90611286565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610b6e92919061115d565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d185760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d045784831415610cf55780600001519350505050610d1f565b8280610d0090611286565b9350505b508080610d1090611286565b915050610b90565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610dd19061125c565b919050555060006003541115610e1f57600254811415610e1a576000610df76000610b85565b90506000811415610e1057600154600281905550610e18565b806002819055505b505b610e29565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610eac816112fe565b92915050565b600081359050610ec181611315565b92915050565b600060208284031215610ed957600080fd5b6000610ee784828501610e9d565b91505092915050565b600080600060608486031215610f0557600080fd5b6000610f1386828701610e9d565b9350506020610f2486828701610e9d565b9250506040610f3586828701610eb2565b9150509250925092565b600060208284031215610f5157600080fd5b6000610f5f84828501610eb2565b91505092915050565b610f71816111e1565b82525050565b610f80816111f3565b82525050565b6000610f9182611186565b610f9b8185611191565b9350610fab818560208601611229565b80840191505092915050565b6000610fc4600d8361119c565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b600061100460138361119c565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110408161121f565b82525050565b60006110528284610f86565b915081905092915050565b60006060820190506110726000830186610f68565b61107f6020830185610f68565b61108c6040830184611037565b949350505050565b60006020820190506110a96000830184610f77565b92915050565b600060208201905081810360008301526110c881610fb7565b9050919050565b600060208201905081810360008301526110e881610ff7565b9050919050565b60006020820190506111046000830184611037565b92915050565b600060a08201905061111f6000830188611037565b61112c6020830187610f68565b6111396040830186610f68565b6111466060830185610f68565b6111536080830184611037565b9695505050505050565b60006040820190506111726000830185611037565b61117f6020830184611037565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006111b88261121f565b91506111c38361121f565b9250828210156111d6576111d56112cf565b5b828203905092915050565b60006111ec826111ff565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561124757808201518184015260208101905061122c565b83811115611256576000848401525b50505050565b60006112678261121f565b9150600082141561127b5761127a6112cf565b5b600182039050919050565b60006112918261121f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156112c4576112c36112cf565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611307816111e1565b811461131257600080fd5b50565b61131e8161121f565b811461132957600080fd5b5056fea26469706673582212209e978aa0a58bb277b43b2787e0c3bd50b7c1ff1cd7010be3f692499c54edc0b364736f6c63430008000033 +\ No newline at end of file diff --git a/python/erc20_approval_escrow/data/TransferApproval.json b/python/erc20_approval_escrow/data/TransferApproval.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] +[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -175,6 +175,24 @@ class Test(unittest.TestCase): self.assertEqual(t.functions.allowances(self.w3.eth.accounts[2], w.address).call(), 0) + def test_indexes(self): + w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) + t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) + + for i in range(0, 5): + amount = 10*(i+1) + sender = self.w3.eth.accounts[3+i]; + tx_hash = w.functions.createRequest(sender, t.address, amount).transact({'from': self.w3.eth.accounts[2]}) + t.functions.approve(w.address, amount).transact({'from': sender}) + self.eth_tester.mine_block() + + w.functions.rejectRequest(1).transact({'from': self.w3.eth.accounts[0]}) + w.functions.rejectRequest(4).transact({'from': self.w3.eth.accounts[0]}) + + assert w.functions.getSerialAt(0).call() == 2 + assert w.functions.getSerialAt(1).call() == 3 + assert w.functions.getSerialAt(2).call() == 5 + def test_index_after_removal(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -222,5 +240,25 @@ class Test(unittest.TestCase): assert (w.functions.lastSerial(). call() == 5) + def test_pass_on_insufficient_approve(self): + w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) + t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) + + self.eth_tester.mine_block() + + w.functions.createRequest(self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[2]}) + tx_hash = w.functions.executeRequest(1).transact({'from': self.w3.eth.accounts[0]}) + + r = self.w3.eth.getTransactionReceipt(tx_hash) + + topic_match = 'dab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb' # TransferFail(uint256) + log = r.logs[0] + topic = log.topics[0] + self.assertEqual(topic.hex()[2:], topic_match) + serial = int(log.data[2:], 16) + + assert serial == 1 + + if __name__ == '__main__': unittest.main() diff --git a/solidity/TransferApproval.bin b/solidity/TransferApproval.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b5060405162001755380380620017558339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b6113d6806200037f6000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c80636e417c69116100665780636e417c691461015d5780637780c14f1461018d57806381d12c58146101ab578063b0addede146101df578063bac911ac1461020f5761009e565b806306661abd146100a357806308ae6377146100c15780630a144391146100df5780632d7788db1461010f57806357ec347a1461013f575b600080fd5b6100ab61023f565b6040516100b89190611163565b60405180910390f35b6100c9610245565b6040516100d69190611163565b60405180910390f35b6100f960048036038101906100f49190610f3b565b610270565b6040516101069190611108565b60405180910390f35b61012960048036038101906101249190610fb3565b610290565b6040516101369190611108565b60405180910390f35b610147610585565b6040516101549190611163565b60405180910390f35b61017760048036038101906101729190610fb3565b61059a565b6040516101849190611108565b60405180910390f35b6101956108c3565b6040516101a29190611163565b60405180910390f35b6101c560048036038101906101c09190610fb3565b6108c9565b6040516101d695949392919061117e565b60405180910390f35b6101f960048036038101906101f49190610f64565b61095f565b6040516102069190611163565b60405180910390f35b61022960048036038101906102249190610fb3565b610bf9565b6040516102369190611163565b60405180910390f35b60035481565b6000806002546001546102589190611221565b1415610267576000905061026d565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661031e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161031590611123565b60405180910390fd5b60008060008481526020019081526020016000209050600081600001541161037b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037290611143565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16856004015460405160240161041a939291906110d1565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516104a491906110ba565b6000604051808303816000865af19150503d80600081146104e1576040519150601f19603f3d011682016040523d82523d6000602084013e6104e6565b606091505b50915091506104f88360000154610d98565b811561053e577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd83600001546040516105319190611163565b60405180910390a161057a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb83600001546040516105719190611163565b60405180910390a15b819350505050919050565b6000600180546105959190611221565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16610628576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161061f90611123565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610685576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161067c90611143565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401610724939291906110d1565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516107ae91906110ba565b6000604051808303816000865af19150503d80600081146107eb576040519150601f19603f3d011682016040523d82523d6000602084013e6107f0565b606091505b509150915081610829577f4e487b7100000000000000000000000000000000000000000000000000000000600052600160045260246000fd5b6108368360000154610d98565b811561087c577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd836000015460405161086f9190611163565b60405180910390a16108b8565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb83600001546040516108af9190611163565b60405180910390a15b819350505050919050565b60025481565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b6000610969610ea0565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610b3b906112fa565b919050555060016000815480929190610b53906112fa565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610be29291906111d1565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d8c5760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d785784831415610d695780600001519350505050610d93565b8280610d74906112fa565b9350505b508080610d84906112fa565b915050610c04565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610e45906112d0565b919050555060006003541115610e9357600254811415610e8e576000610e6b6000610bf9565b90506000811415610e8457600154600281905550610e8c565b806002819055505b505b610e9d565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610f2081611372565b92915050565b600081359050610f3581611389565b92915050565b600060208284031215610f4d57600080fd5b6000610f5b84828501610f11565b91505092915050565b600080600060608486031215610f7957600080fd5b6000610f8786828701610f11565b9350506020610f9886828701610f11565b9250506040610fa986828701610f26565b9150509250925092565b600060208284031215610fc557600080fd5b6000610fd384828501610f26565b91505092915050565b610fe581611255565b82525050565b610ff481611267565b82525050565b6000611005826111fa565b61100f8185611205565b935061101f81856020860161129d565b80840191505092915050565b6000611038600d83611210565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b6000611078601383611210565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110b481611293565b82525050565b60006110c68284610ffa565b915081905092915050565b60006060820190506110e66000830186610fdc565b6110f36020830185610fdc565b61110060408301846110ab565b949350505050565b600060208201905061111d6000830184610feb565b92915050565b6000602082019050818103600083015261113c8161102b565b9050919050565b6000602082019050818103600083015261115c8161106b565b9050919050565b600060208201905061117860008301846110ab565b92915050565b600060a08201905061119360008301886110ab565b6111a06020830187610fdc565b6111ad6040830186610fdc565b6111ba6060830185610fdc565b6111c760808301846110ab565b9695505050505050565b60006040820190506111e660008301856110ab565b6111f360208301846110ab565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b600061122c82611293565b915061123783611293565b92508282101561124a57611249611343565b5b828203905092915050565b600061126082611273565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156112bb5780820151818401526020810190506112a0565b838111156112ca576000848401525b50505050565b60006112db82611293565b915060008214156112ef576112ee611343565b5b600182039050919050565b600061130582611293565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82141561133857611337611343565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b61137b81611255565b811461138657600080fd5b50565b61139281611293565b811461139d57600080fd5b5056fea2646970667358221220d441a811b83873b5e6f885838296dc5de101a07165838838514de472d224d11f64736f6c63430008000033 -\ No newline at end of file +60806040523480156200001157600080fd5b50604051620016e1380380620016e18339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b611362806200037f6000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806357ec347a1161006657806357ec347a146101345780636e417c691461015257806381d12c5814610182578063b0addede146101b6578063bac911ac146101e657610093565b806306661abd1461009857806308ae6377146100b65780630a144391146100d45780632d7788db14610104575b600080fd5b6100a0610216565b6040516100ad91906110ef565b60405180910390f35b6100be61021c565b6040516100cb91906110ef565b60405180910390f35b6100ee60048036038101906100e99190610ec7565b610247565b6040516100fb9190611094565b60405180910390f35b61011e60048036038101906101199190610f3f565b610267565b60405161012b9190611094565b60405180910390f35b61013c610553565b60405161014991906110ef565b60405180910390f35b61016c60048036038101906101679190610f3f565b610568565b6040516101799190611094565b60405180910390f35b61019c60048036038101906101979190610f3f565b610855565b6040516101ad95949392919061110a565b60405180910390f35b6101d060048036038101906101cb9190610ef0565b6108eb565b6040516101dd91906110ef565b60405180910390f35b61020060048036038101906101fb9190610f3f565b610b85565b60405161020d91906110ef565b60405180910390f35b60035481565b60008060025460015461022f91906111ad565b141561023e5760009050610244565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166102f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ec906110af565b60405180910390fd5b6000806000848152602001908152602001600020905082816000015414610351576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610348906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016103f09392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161047a9190611046565b6000604051808303816000865af19150503d80600081146104b7576040519150601f19603f3d011682016040523d82523d6000602084013e6104bc565b606091505b50915091506104ce8360000154610d24565b8115610510577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161050391906110ef565b60405180910390a1610548565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161053f91906110ef565b60405180910390a15b819350505050919050565b60006001805461056391906111ad565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105ed906110af565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610653576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161064a906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016106f29392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161077c9190611046565b6000604051808303816000865af19150503d80600081146107b9576040519150601f19603f3d011682016040523d82523d6000602084013e6107be565b606091505b50915091506107d08360000154610d24565b8115610812577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161080591906110ef565b60405180910390a161084a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161084191906110ef565b60405180910390a15b819350505050919050565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b60006108f5610e2c565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610ac790611286565b919050555060016000815480929190610adf90611286565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610b6e92919061115d565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d185760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d045784831415610cf55780600001519350505050610d1f565b8280610d0090611286565b9350505b508080610d1090611286565b915050610b90565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610dd19061125c565b919050555060006003541115610e1f57600254811415610e1a576000610df76000610b85565b90506000811415610e1057600154600281905550610e18565b806002819055505b505b610e29565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610eac816112fe565b92915050565b600081359050610ec181611315565b92915050565b600060208284031215610ed957600080fd5b6000610ee784828501610e9d565b91505092915050565b600080600060608486031215610f0557600080fd5b6000610f1386828701610e9d565b9350506020610f2486828701610e9d565b9250506040610f3586828701610eb2565b9150509250925092565b600060208284031215610f5157600080fd5b6000610f5f84828501610eb2565b91505092915050565b610f71816111e1565b82525050565b610f80816111f3565b82525050565b6000610f9182611186565b610f9b8185611191565b9350610fab818560208601611229565b80840191505092915050565b6000610fc4600d8361119c565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b600061100460138361119c565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110408161121f565b82525050565b60006110528284610f86565b915081905092915050565b60006060820190506110726000830186610f68565b61107f6020830185610f68565b61108c6040830184611037565b949350505050565b60006020820190506110a96000830184610f77565b92915050565b600060208201905081810360008301526110c881610fb7565b9050919050565b600060208201905081810360008301526110e881610ff7565b9050919050565b60006020820190506111046000830184611037565b92915050565b600060a08201905061111f6000830188611037565b61112c6020830187610f68565b6111396040830186610f68565b6111466060830185610f68565b6111536080830184611037565b9695505050505050565b60006040820190506111726000830185611037565b61117f6020830184611037565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006111b88261121f565b91506111c38361121f565b9250828210156111d6576111d56112cf565b5b828203905092915050565b60006111ec826111ff565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561124757808201518184015260208101905061122c565b83811115611256576000848401525b50505050565b60006112678261121f565b9150600082141561127b5761127a6112cf565b5b600182039050919050565b60006112918261121f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156112c4576112c36112cf565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611307816111e1565b811461131257600080fd5b50565b61131e8161121f565b811461132957600080fd5b5056fea26469706673582212209e978aa0a58bb277b43b2787e0c3bd50b7c1ff1cd7010be3f692499c54edc0b364736f6c63430008000033 +\ No newline at end of file diff --git a/solidity/TransferApproval.json b/solidity/TransferApproval.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lo","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] +[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] diff --git a/solidity/TransferApproval.sol b/solidity/TransferApproval.sol @@ -10,11 +10,9 @@ contract ERC20ApprovalEscrow { address token; uint256 value; } - //mapping(uint256 => Transaction) public requests; mapping(uint256 => Transaction) public requests; - //Transaction[] public requests; uint256 hi; - uint256 public lo; + uint256 lo; uint256 public count; mapping(address => bool) public approvers; @@ -51,10 +49,6 @@ contract ERC20ApprovalEscrow { } function removeItem(uint256 serialToRemove) private { - //Transaction memory lastTxx = requests[requests.length-1]; - //requests.pop(); - //uint256 idxToReplace = requests[serialToRemove]; - delete requests[serialToRemove]; count--; @@ -105,14 +99,13 @@ contract ERC20ApprovalEscrow { require(txx.serial > 0, 'ERR_INVALID_REQUEST'); (bool success, bytes memory _r) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.recipient, txx.value)); - assert(success); removeItem(txx.serial); if (success) { - emit NewRejection(txx.serial); + emit NewRejection(_serial); } else { - emit TransferFail(txx.serial); + emit TransferFail(_serial); } return success; @@ -122,20 +115,18 @@ contract ERC20ApprovalEscrow { require(approvers[msg.sender], 'ERR_NO_ACCESS'); Transaction storage txx = requests[_serial]; - require(txx.serial > 0, 'ERR_INVALID_REQUEST'); + require(txx.serial == _serial, 'ERR_INVALID_REQUEST'); (bool success, bytes memory _r) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.sender, txx.value)); removeItem(txx.serial); if (success) { - emit NewRejection(txx.serial); + emit NewRejection(_serial); } else { - emit TransferFail(txx.serial); + emit TransferFail(_serial); } - //delete requests[txx.serial]; - return success; } }