diff --git a/.gitignore b/.gitignore index 5a8a8f3..c06d791 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ mytestnet coverage.txt profile.out sim_log_file +testdata # Vagrant .vagrant/ diff --git a/Makefile b/Makefile index 0170163..03dc0bb 100644 --- a/Makefile +++ b/Makefile @@ -201,6 +201,9 @@ contracts-gen: $(CONTRACTS_DIR)/* benchmark: @go test -timeout 20m -mod=readonly -bench=. ./... +fuzz: + @go test --timeout 2m -mod=readonly -fuzz=Fuzz ./x/evm/keeper + .PHONY: test test-all test-cover test-unit test-race benchmark contracts-gen ############################################################################### diff --git a/x/evm/contracts/counter/Counter.go b/x/evm/contracts/counter/Counter.go index 0b9ce07..83a39d6 100644 --- a/x/evm/contracts/counter/Counter.go +++ b/x/evm/contracts/counter/Counter.go @@ -31,8 +31,8 @@ var ( // CounterMetaData contains all meta data concerning the Counter contract. var CounterMetaData = &bind.MetaData{ - ABI: "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"length\",\"type\":\"uint256\"}],\"name\":\"StringsInsufficientHexLength\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"callback_received\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"oldCount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"newCount\",\"type\":\"uint256\"}],\"name\":\"increased\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"recursive_called\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"callback\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"count\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"exec_msg\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"call_revert\",\"type\":\"bool\"}],\"name\":\"execute_cosmos\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"exec_msg\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"allow_failure\",\"type\":\"bool\"},{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"execute_cosmos_with_options\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"get_blockhash\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"ibc_ack\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"ibc_timeout\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"increase\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"path\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"req\",\"type\":\"string\"}],\"name\":\"query_cosmos\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"result\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"recursive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", - Bin: "0x608060405261196b806100115f395ff3fe608060405260043610610090575f3560e01c80637876da75116100585780637876da751461015e578063ac7fde5f14610186578063c31925a7146101c2578063cad23554146101ea578063e8927fbc1461022657610090565b806306661abd146100945780630d4f1f9d146100be57806324c68fce146100e657806331a503f01461010e5780636193689514610136575b5f80fd5b34801561009f575f80fd5b506100a8610230565b6040516100b59190610ca1565b60405180910390f35b3480156100c9575f80fd5b506100e460048036038101906100df9190610d3d565b610235565b005b3480156100f1575f80fd5b5061010c60048036038101906101079190610eb7565b61027c565b005b348015610119575f80fd5b50610134600480360381019061012f9190610f11565b61033c565b005b348015610141575f80fd5b5061015c60048036038101906101579190610f11565b610360565b005b348015610169575f80fd5b50610184600480360381019061017f9190610f3c565b6104b3565b005b348015610191575f80fd5b506101ac60048036038101906101a79190610f11565b610555565b6040516101b99190610fc0565b60405180910390f35b3480156101cd575f80fd5b506101e860048036038101906101e39190610d3d565b610569565b005b3480156101f5575f80fd5b50610210600480360381019061020b9190610fd9565b6105a6565b60405161021d91906110af565b60405180910390f35b61022e61062f565b005b5f5481565b8015610261578167ffffffffffffffff165f8082825461025591906110fc565b92505081905550610278565b5f808154809291906102729061112f565b91905055505b5050565b60f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e6836040518263ffffffff1660e01b81526004016102b691906110af565b6020604051808303815f875af11580156102d2573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906102f6919061118a565b508015610338576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161032f90611225565b60405180910390fd5b5050565b8067ffffffffffffffff165f8082825461035691906110fc565b9250508190555050565b7f4475bbd12ef452e28d39c4cb77494d85136c2d89ca1354b52188d4aaa8f4ba518160405161038f9190611252565b60405180910390a15f8167ffffffffffffffff1603156104b05760f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e66103cf8361068e565b6040518263ffffffff1660e01b81526004016103eb91906110af565b6020604051808303815f875af1158015610407573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061042b919061118a565b5060f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e66104528361068e565b6040518263ffffffff1660e01b815260040161046e91906110af565b6020604051808303815f875af115801561048a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906104ae919061118a565b505b50565b60f173ffffffffffffffffffffffffffffffffffffffff16636c4f6bd584604051806040016040528086151581526020018567ffffffffffffffff168152506040518363ffffffff1660e01b815260040161050f9291906112b6565b6020604051808303815f875af115801561052b573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061054f919061118a565b50505050565b5f8167ffffffffffffffff16409050919050565b7fa019c7431cdfd7ba63501ffa1ba7d8f2a028e447653a5af5a96077e5038e0339828260405161059a9291906112f3565b60405180910390a15050565b606060f173ffffffffffffffffffffffffffffffffffffffff1663cad2355484846040518363ffffffff1660e01b81526004016105e492919061131a565b5f604051808303815f875af11580156105ff573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061062791906113bd565b905092915050565b5f808154809291906106409061112f565b91905055507f61996fe196f72cb598c483e896a1221263a28bb630480aa89495f737d4a8e3df60015f546106749190611404565b5f54604051610684929190611437565b60405180910390a1565b606060f173ffffffffffffffffffffffffffffffffffffffff16636af32a55306040518263ffffffff1660e01b81526004016106ca919061149d565b5f604051808303815f875af11580156106e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061070d91906113bd565b6107163061079a565b610772636193689560e01b60018661072e91906114b6565b60405160200161073e9190611252565b60405160208183030381529060405260405160200161075e929190611580565b6040516020818303038152906040526107c7565b6040516020016107849392919061180d565b6040516020818303038152906040529050919050565b60606107c08273ffffffffffffffffffffffffffffffffffffffff16601460ff16610a4b565b9050919050565b60605f60028084516107d991906118a0565b6107e391906110fc565b67ffffffffffffffff8111156107fc576107fb610d93565b5b6040519080825280601f01601f19166020018201604052801561082e5781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f81518110610865576108646118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106108c8576108c76118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f5b8351811015610a41575f848281518110610915576109146118e1565b5b602001015160f81c60f81b60f81c90507f303132333435363738396162636465660000000000000000000000000000000060048260ff16901c60ff1660108110610962576109616118e1565b5b1a60f81b836002808502018151811061097e5761097d6118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f3031323334353637383961626364656600000000000000000000000000000000600f821660ff16601081106109e5576109e46118e1565b5b1a60f81b836002600160028602010181518110610a0557610a046118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505080806001019150506108f8565b5080915050919050565b60605f8390505f6002846002610a6191906118a0565b610a6b91906110fc565b67ffffffffffffffff811115610a8457610a83610d93565b5b6040519080825280601f01601f191660200182016040528015610ab65781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f81518110610aed57610aec6118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610b5057610b4f6118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f6001856002610b8e91906118a0565b610b9891906110fc565b90505b6001811115610c37577f3031323334353637383961626364656600000000000000000000000000000000600f841660108110610bda57610bd96118e1565b5b1a60f81b828281518110610bf157610bf06118e1565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350600483901c925080610c309061190e565b9050610b9b565b505f8214610c7e5784846040517fe22e27eb000000000000000000000000000000000000000000000000000000008152600401610c75929190611437565b60405180910390fd5b809250505092915050565b5f819050919050565b610c9b81610c89565b82525050565b5f602082019050610cb45f830184610c92565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f67ffffffffffffffff82169050919050565b610ce781610ccb565b8114610cf1575f80fd5b50565b5f81359050610d0281610cde565b92915050565b5f8115159050919050565b610d1c81610d08565b8114610d26575f80fd5b50565b5f81359050610d3781610d13565b92915050565b5f8060408385031215610d5357610d52610cc3565b5b5f610d6085828601610cf4565b9250506020610d7185828601610d29565b9150509250929050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b610dc982610d83565b810181811067ffffffffffffffff82111715610de857610de7610d93565b5b80604052505050565b5f610dfa610cba565b9050610e068282610dc0565b919050565b5f67ffffffffffffffff821115610e2557610e24610d93565b5b610e2e82610d83565b9050602081019050919050565b828183375f83830152505050565b5f610e5b610e5684610e0b565b610df1565b905082815260208101848484011115610e7757610e76610d7f565b5b610e82848285610e3b565b509392505050565b5f82601f830112610e9e57610e9d610d7b565b5b8135610eae848260208601610e49565b91505092915050565b5f8060408385031215610ecd57610ecc610cc3565b5b5f83013567ffffffffffffffff811115610eea57610ee9610cc7565b5b610ef685828601610e8a565b9250506020610f0785828601610d29565b9150509250929050565b5f60208284031215610f2657610f25610cc3565b5b5f610f3384828501610cf4565b91505092915050565b5f805f60608486031215610f5357610f52610cc3565b5b5f84013567ffffffffffffffff811115610f7057610f6f610cc7565b5b610f7c86828701610e8a565b9350506020610f8d86828701610d29565b9250506040610f9e86828701610cf4565b9150509250925092565b5f819050919050565b610fba81610fa8565b82525050565b5f602082019050610fd35f830184610fb1565b92915050565b5f8060408385031215610fef57610fee610cc3565b5b5f83013567ffffffffffffffff81111561100c5761100b610cc7565b5b61101885828601610e8a565b925050602083013567ffffffffffffffff81111561103957611038610cc7565b5b61104585828601610e8a565b9150509250929050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f6110818261104f565b61108b8185611059565b935061109b818560208601611069565b6110a481610d83565b840191505092915050565b5f6020820190508181035f8301526110c78184611077565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61110682610c89565b915061111183610c89565b9250828201905080821115611129576111286110cf565b5b92915050565b5f61113982610c89565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361116b5761116a6110cf565b5b600182019050919050565b5f8151905061118481610d13565b92915050565b5f6020828403121561119f5761119e610cc3565b5b5f6111ac84828501611176565b91505092915050565b7f72657665727420726561736f6e2064756d6d792076616c756520666f722074655f8201527f7374000000000000000000000000000000000000000000000000000000000000602082015250565b5f61120f602283611059565b915061121a826111b5565b604082019050919050565b5f6020820190508181035f83015261123c81611203565b9050919050565b61124c81610ccb565b82525050565b5f6020820190506112655f830184611243565b92915050565b61127481610d08565b82525050565b61128381610ccb565b82525050565b604082015f82015161129d5f85018261126b565b5060208201516112b0602085018261127a565b50505050565b5f6060820190508181035f8301526112ce8185611077565b90506112dd6020830184611289565b9392505050565b6112ed81610d08565b82525050565b5f6040820190506113065f830185611243565b61131360208301846112e4565b9392505050565b5f6040820190508181035f8301526113328185611077565b905081810360208301526113468184611077565b90509392505050565b5f61136161135c84610e0b565b610df1565b90508281526020810184848401111561137d5761137c610d7f565b5b611388848285611069565b509392505050565b5f82601f8301126113a4576113a3610d7b565b5b81516113b484826020860161134f565b91505092915050565b5f602082840312156113d2576113d1610cc3565b5b5f82015167ffffffffffffffff8111156113ef576113ee610cc7565b5b6113fb84828501611390565b91505092915050565b5f61140e82610c89565b915061141983610c89565b9250828203905081811115611431576114306110cf565b5b92915050565b5f60408201905061144a5f830185610c92565b6114576020830184610c92565b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6114878261145e565b9050919050565b6114978161147d565b82525050565b5f6020820190506114b05f83018461148e565b92915050565b5f6114c082610ccb565b91506114cb83610ccb565b9250828203905067ffffffffffffffff8111156114eb576114ea6110cf565b5b92915050565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b5f819050919050565b611536611531826114f1565b61151c565b82525050565b5f81519050919050565b5f81905092915050565b5f61155a8261153c565b6115648185611546565b9350611574818560208601611069565b80840191505092915050565b5f61158b8285611525565b60048201915061159b8284611550565b91508190509392505050565b5f81905092915050565b7f7b224074797065223a20222f6d696e6965766d2e65766d2e76312e4d736743615f8201527f6c6c222c00000000000000000000000000000000000000000000000000000000602082015250565b5f61160b6024836115a7565b9150611616826115b1565b602482019050919050565b7f2273656e646572223a20220000000000000000000000000000000000000000005f82015250565b5f611655600b836115a7565b915061166082611621565b600b82019050919050565b5f6116758261104f565b61167f81856115a7565b935061168f818560208601611069565b80840191505092915050565b7f222c0000000000000000000000000000000000000000000000000000000000005f82015250565b5f6116cf6002836115a7565b91506116da8261169b565b600282019050919050565b7f22636f6e74726163745f61646472223a202200000000000000000000000000005f82015250565b5f6117196012836115a7565b9150611724826116e5565b601282019050919050565b7f22696e707574223a2022000000000000000000000000000000000000000000005f82015250565b5f611763600a836115a7565b915061176e8261172f565b600a82019050919050565b7f2276616c7565223a202230222c000000000000000000000000000000000000005f82015250565b5f6117ad600d836115a7565b91506117b882611779565b600d82019050919050565b7f226163636573735f6c697374223a205b5d7d00000000000000000000000000005f82015250565b5f6117f76012836115a7565b9150611802826117c3565b601282019050919050565b5f611817826115ff565b915061182282611649565b915061182e828661166b565b9150611839826116c3565b91506118448261170d565b9150611850828561166b565b915061185b826116c3565b915061186682611757565b9150611872828461166b565b915061187d826116c3565b9150611888826117a1565b9150611893826117eb565b9150819050949350505050565b5f6118aa82610c89565b91506118b583610c89565b92508282026118c381610c89565b915082820484148315176118da576118d96110cf565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f61191882610c89565b91505f820361192a576119296110cf565b5b60018203905091905056fea2646970667358221220232e4a59c853984a75103129e9f3653dfa3c427f01a17f8e49f2ad464aa328d464736f6c63430008190033", + ABI: "[{\"inputs\":[],\"stateMutability\":\"payable\",\"type\":\"constructor\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"value\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"length\",\"type\":\"uint256\"}],\"name\":\"StringsInsufficientHexLength\",\"type\":\"error\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"indexed\":false,\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"callback_received\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"oldCount\",\"type\":\"uint256\"},{\"indexed\":false,\"internalType\":\"uint256\",\"name\":\"newCount\",\"type\":\"uint256\"}],\"name\":\"increased\",\"type\":\"event\"},{\"anonymous\":false,\"inputs\":[{\"indexed\":false,\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"recursive_called\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"callback\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"count\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"exec_msg\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"call_revert\",\"type\":\"bool\"}],\"name\":\"execute_cosmos\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"exec_msg\",\"type\":\"string\"},{\"internalType\":\"bool\",\"name\":\"allow_failure\",\"type\":\"bool\"},{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"execute_cosmos_with_options\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"get_blockhash\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"},{\"internalType\":\"bool\",\"name\":\"success\",\"type\":\"bool\"}],\"name\":\"ibc_ack\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"callback_id\",\"type\":\"uint64\"}],\"name\":\"ibc_timeout\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"increase\",\"outputs\":[],\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"num\",\"type\":\"uint64\"}],\"name\":\"increase_for_fuzz\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"path\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"req\",\"type\":\"string\"}],\"name\":\"query_cosmos\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"result\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint64\",\"name\":\"n\",\"type\":\"uint64\"}],\"name\":\"recursive\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]", + Bin: "0x60806040526119d5806100115f395ff3fe60806040526004361061009b575f3560e01c8063619368951161006357806361936895146101695780637876da7514610191578063ac7fde5f146101b9578063c31925a7146101f5578063cad235541461021d578063e8927fbc146102595761009b565b806306661abd1461009f5780630d4f1f9d146100c957806324c68fce146100f15780632607baf81461011957806331a503f014610141575b5f80fd5b3480156100aa575f80fd5b506100b3610263565b6040516100c09190610d0b565b60405180910390f35b3480156100d4575f80fd5b506100ef60048036038101906100ea9190610da7565b610268565b005b3480156100fc575f80fd5b5061011760048036038101906101129190610f21565b6102af565b005b348015610124575f80fd5b5061013f600480360381019061013a9190610f7b565b61036f565b005b34801561014c575f80fd5b5061016760048036038101906101629190610f7b565b6103a6565b005b348015610174575f80fd5b5061018f600480360381019061018a9190610f7b565b6103ca565b005b34801561019c575f80fd5b506101b760048036038101906101b29190610fa6565b61051d565b005b3480156101c4575f80fd5b506101df60048036038101906101da9190610f7b565b6105bf565b6040516101ec919061102a565b60405180910390f35b348015610200575f80fd5b5061021b60048036038101906102169190610da7565b6105d3565b005b348015610228575f80fd5b50610243600480360381019061023e9190611043565b610610565b6040516102509190611119565b60405180910390f35b610261610699565b005b5f5481565b8015610294578167ffffffffffffffff165f808282546102889190611166565b925050819055506102ab565b5f808154809291906102a590611199565b91905055505b5050565b60f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e6836040518263ffffffff1660e01b81526004016102e99190611119565b6020604051808303815f875af1158015610305573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061032991906111f4565b50801561036b576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103629061128f565b60405180910390fd5b5050565b5f5b8167ffffffffffffffff168167ffffffffffffffff1610156103a257610395610699565b8080600101915050610371565b5050565b8067ffffffffffffffff165f808282546103c09190611166565b9250508190555050565b7f4475bbd12ef452e28d39c4cb77494d85136c2d89ca1354b52188d4aaa8f4ba51816040516103f991906112bc565b60405180910390a15f8167ffffffffffffffff16031561051a5760f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e6610439836106f8565b6040518263ffffffff1660e01b81526004016104559190611119565b6020604051808303815f875af1158015610471573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061049591906111f4565b5060f173ffffffffffffffffffffffffffffffffffffffff1663d46f64e66104bc836106f8565b6040518263ffffffff1660e01b81526004016104d89190611119565b6020604051808303815f875af11580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061051891906111f4565b505b50565b60f173ffffffffffffffffffffffffffffffffffffffff16636c4f6bd584604051806040016040528086151581526020018567ffffffffffffffff168152506040518363ffffffff1660e01b8152600401610579929190611320565b6020604051808303815f875af1158015610595573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105b991906111f4565b50505050565b5f8167ffffffffffffffff16409050919050565b7fa019c7431cdfd7ba63501ffa1ba7d8f2a028e447653a5af5a96077e5038e0339828260405161060492919061135d565b60405180910390a15050565b606060f173ffffffffffffffffffffffffffffffffffffffff1663cad2355484846040518363ffffffff1660e01b815260040161064e929190611384565b5f604051808303815f875af1158015610669573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906106919190611427565b905092915050565b5f808154809291906106aa90611199565b91905055507f61996fe196f72cb598c483e896a1221263a28bb630480aa89495f737d4a8e3df60015f546106de919061146e565b5f546040516106ee9291906114a1565b60405180910390a1565b606060f173ffffffffffffffffffffffffffffffffffffffff16636af32a55306040518263ffffffff1660e01b81526004016107349190611507565b5f604051808303815f875af115801561074f573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906107779190611427565b61078030610804565b6107dc636193689560e01b6001866107989190611520565b6040516020016107a891906112bc565b6040516020818303038152906040526040516020016107c89291906115ea565b604051602081830303815290604052610831565b6040516020016107ee93929190611877565b6040516020818303038152906040529050919050565b606061082a8273ffffffffffffffffffffffffffffffffffffffff16601460ff16610ab5565b9050919050565b60605f6002808451610843919061190a565b61084d9190611166565b67ffffffffffffffff81111561086657610865610dfd565b5b6040519080825280601f01601f1916602001820160405280156108985781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f815181106108cf576108ce61194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106109325761093161194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f5b8351811015610aab575f84828151811061097f5761097e61194b565b5b602001015160f81c60f81b60f81c90507f303132333435363738396162636465660000000000000000000000000000000060048260ff16901c60ff16601081106109cc576109cb61194b565b5b1a60f81b83600280850201815181106109e8576109e761194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f3031323334353637383961626364656600000000000000000000000000000000600f821660ff1660108110610a4f57610a4e61194b565b5b1a60f81b836002600160028602010181518110610a6f57610a6e61194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350508080600101915050610962565b5080915050919050565b60605f8390505f6002846002610acb919061190a565b610ad59190611166565b67ffffffffffffffff811115610aee57610aed610dfd565b5b6040519080825280601f01601f191660200182016040528015610b205781602001600182028036833780820191505090505b5090507f3000000000000000000000000000000000000000000000000000000000000000815f81518110610b5757610b5661194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053507f780000000000000000000000000000000000000000000000000000000000000081600181518110610bba57610bb961194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a9053505f6001856002610bf8919061190a565b610c029190611166565b90505b6001811115610ca1577f3031323334353637383961626364656600000000000000000000000000000000600f841660108110610c4457610c4361194b565b5b1a60f81b828281518110610c5b57610c5a61194b565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191690815f1a905350600483901c925080610c9a90611978565b9050610c05565b505f8214610ce85784846040517fe22e27eb000000000000000000000000000000000000000000000000000000008152600401610cdf9291906114a1565b60405180910390fd5b809250505092915050565b5f819050919050565b610d0581610cf3565b82525050565b5f602082019050610d1e5f830184610cfc565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f67ffffffffffffffff82169050919050565b610d5181610d35565b8114610d5b575f80fd5b50565b5f81359050610d6c81610d48565b92915050565b5f8115159050919050565b610d8681610d72565b8114610d90575f80fd5b50565b5f81359050610da181610d7d565b92915050565b5f8060408385031215610dbd57610dbc610d2d565b5b5f610dca85828601610d5e565b9250506020610ddb85828601610d93565b9150509250929050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b610e3382610ded565b810181811067ffffffffffffffff82111715610e5257610e51610dfd565b5b80604052505050565b5f610e64610d24565b9050610e708282610e2a565b919050565b5f67ffffffffffffffff821115610e8f57610e8e610dfd565b5b610e9882610ded565b9050602081019050919050565b828183375f83830152505050565b5f610ec5610ec084610e75565b610e5b565b905082815260208101848484011115610ee157610ee0610de9565b5b610eec848285610ea5565b509392505050565b5f82601f830112610f0857610f07610de5565b5b8135610f18848260208601610eb3565b91505092915050565b5f8060408385031215610f3757610f36610d2d565b5b5f83013567ffffffffffffffff811115610f5457610f53610d31565b5b610f6085828601610ef4565b9250506020610f7185828601610d93565b9150509250929050565b5f60208284031215610f9057610f8f610d2d565b5b5f610f9d84828501610d5e565b91505092915050565b5f805f60608486031215610fbd57610fbc610d2d565b5b5f84013567ffffffffffffffff811115610fda57610fd9610d31565b5b610fe686828701610ef4565b9350506020610ff786828701610d93565b925050604061100886828701610d5e565b9150509250925092565b5f819050919050565b61102481611012565b82525050565b5f60208201905061103d5f83018461101b565b92915050565b5f806040838503121561105957611058610d2d565b5b5f83013567ffffffffffffffff81111561107657611075610d31565b5b61108285828601610ef4565b925050602083013567ffffffffffffffff8111156110a3576110a2610d31565b5b6110af85828601610ef4565b9150509250929050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f6110eb826110b9565b6110f581856110c3565b93506111058185602086016110d3565b61110e81610ded565b840191505092915050565b5f6020820190508181035f83015261113181846110e1565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61117082610cf3565b915061117b83610cf3565b925082820190508082111561119357611192611139565b5b92915050565b5f6111a382610cf3565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036111d5576111d4611139565b5b600182019050919050565b5f815190506111ee81610d7d565b92915050565b5f6020828403121561120957611208610d2d565b5b5f611216848285016111e0565b91505092915050565b7f72657665727420726561736f6e2064756d6d792076616c756520666f722074655f8201527f7374000000000000000000000000000000000000000000000000000000000000602082015250565b5f6112796022836110c3565b91506112848261121f565b604082019050919050565b5f6020820190508181035f8301526112a68161126d565b9050919050565b6112b681610d35565b82525050565b5f6020820190506112cf5f8301846112ad565b92915050565b6112de81610d72565b82525050565b6112ed81610d35565b82525050565b604082015f8201516113075f8501826112d5565b50602082015161131a60208501826112e4565b50505050565b5f6060820190508181035f83015261133881856110e1565b905061134760208301846112f3565b9392505050565b61135781610d72565b82525050565b5f6040820190506113705f8301856112ad565b61137d602083018461134e565b9392505050565b5f6040820190508181035f83015261139c81856110e1565b905081810360208301526113b081846110e1565b90509392505050565b5f6113cb6113c684610e75565b610e5b565b9050828152602081018484840111156113e7576113e6610de9565b5b6113f28482856110d3565b509392505050565b5f82601f83011261140e5761140d610de5565b5b815161141e8482602086016113b9565b91505092915050565b5f6020828403121561143c5761143b610d2d565b5b5f82015167ffffffffffffffff81111561145957611458610d31565b5b611465848285016113fa565b91505092915050565b5f61147882610cf3565b915061148383610cf3565b925082820390508181111561149b5761149a611139565b5b92915050565b5f6040820190506114b45f830185610cfc565b6114c16020830184610cfc565b9392505050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6114f1826114c8565b9050919050565b611501816114e7565b82525050565b5f60208201905061151a5f8301846114f8565b92915050565b5f61152a82610d35565b915061153583610d35565b9250828203905067ffffffffffffffff81111561155557611554611139565b5b92915050565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b5f819050919050565b6115a061159b8261155b565b611586565b82525050565b5f81519050919050565b5f81905092915050565b5f6115c4826115a6565b6115ce81856115b0565b93506115de8185602086016110d3565b80840191505092915050565b5f6115f5828561158f565b60048201915061160582846115ba565b91508190509392505050565b5f81905092915050565b7f7b224074797065223a20222f6d696e6965766d2e65766d2e76312e4d736743615f8201527f6c6c222c00000000000000000000000000000000000000000000000000000000602082015250565b5f611675602483611611565b91506116808261161b565b602482019050919050565b7f2273656e646572223a20220000000000000000000000000000000000000000005f82015250565b5f6116bf600b83611611565b91506116ca8261168b565b600b82019050919050565b5f6116df826110b9565b6116e98185611611565b93506116f98185602086016110d3565b80840191505092915050565b7f222c0000000000000000000000000000000000000000000000000000000000005f82015250565b5f611739600283611611565b915061174482611705565b600282019050919050565b7f22636f6e74726163745f61646472223a202200000000000000000000000000005f82015250565b5f611783601283611611565b915061178e8261174f565b601282019050919050565b7f22696e707574223a2022000000000000000000000000000000000000000000005f82015250565b5f6117cd600a83611611565b91506117d882611799565b600a82019050919050565b7f2276616c7565223a202230222c000000000000000000000000000000000000005f82015250565b5f611817600d83611611565b9150611822826117e3565b600d82019050919050565b7f226163636573735f6c697374223a205b5d7d00000000000000000000000000005f82015250565b5f611861601283611611565b915061186c8261182d565b601282019050919050565b5f61188182611669565b915061188c826116b3565b915061189882866116d5565b91506118a38261172d565b91506118ae82611777565b91506118ba82856116d5565b91506118c58261172d565b91506118d0826117c1565b91506118dc82846116d5565b91506118e78261172d565b91506118f28261180b565b91506118fd82611855565b9150819050949350505050565b5f61191482610cf3565b915061191f83610cf3565b925082820261192d81610cf3565b9150828204841483151761194457611943611139565b5b5092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f61198282610cf3565b91505f820361199457611993611139565b5b60018203905091905056fea26469706673582212200a7ce0e26acba95a7c743fdbda8b71ca05f740d34c3da66a5071051ea3eb6c0a64736f6c63430008190033", } // CounterABI is the input ABI used to generate the binding from. @@ -390,6 +390,27 @@ func (_Counter *CounterTransactorSession) Increase() (*types.Transaction, error) return _Counter.Contract.Increase(&_Counter.TransactOpts) } +// IncreaseForFuzz is a paid mutator transaction binding the contract method 0x2607baf8. +// +// Solidity: function increase_for_fuzz(uint64 num) returns() +func (_Counter *CounterTransactor) IncreaseForFuzz(opts *bind.TransactOpts, num uint64) (*types.Transaction, error) { + return _Counter.contract.Transact(opts, "increase_for_fuzz", num) +} + +// IncreaseForFuzz is a paid mutator transaction binding the contract method 0x2607baf8. +// +// Solidity: function increase_for_fuzz(uint64 num) returns() +func (_Counter *CounterSession) IncreaseForFuzz(num uint64) (*types.Transaction, error) { + return _Counter.Contract.IncreaseForFuzz(&_Counter.TransactOpts, num) +} + +// IncreaseForFuzz is a paid mutator transaction binding the contract method 0x2607baf8. +// +// Solidity: function increase_for_fuzz(uint64 num) returns() +func (_Counter *CounterTransactorSession) IncreaseForFuzz(num uint64) (*types.Transaction, error) { + return _Counter.Contract.IncreaseForFuzz(&_Counter.TransactOpts, num) +} + // QueryCosmos is a paid mutator transaction binding the contract method 0xcad23554. // // Solidity: function query_cosmos(string path, string req) returns(string result) diff --git a/x/evm/contracts/counter/Counter.sol b/x/evm/contracts/counter/Counter.sol index 12c7281..71c1459 100644 --- a/x/evm/contracts/counter/Counter.sol +++ b/x/evm/contracts/counter/Counter.sol @@ -14,7 +14,13 @@ contract Counter is IIBCAsyncCallback { constructor() payable {} - function increase() external payable { + function increase_for_fuzz(uint64 num) external { + for (uint64 i = 0; i < num; i++) { + increase(); + } + } + + function increase() public payable { count++; emit increased(count - 1, count); diff --git a/x/evm/keeper/context_test.go b/x/evm/keeper/context_test.go index 0748457..0bee118 100644 --- a/x/evm/keeper/context_test.go +++ b/x/evm/keeper/context_test.go @@ -118,7 +118,7 @@ func Test_Call(t *testing.T) { res, logs, err := input.EVMKeeper.EVMCall(ctx, caller, contractAddr, inputBz, uint256.NewInt(100), nil) require.NoError(t, err) require.Empty(t, res) - require.NotEmpty(t, logs) + require.Len(t, logs, int(2)) // check balance balance, err := input.EVMKeeper.ERC20Keeper().GetBalance(ctx, contractAddr.Bytes(), sdk.DefaultBondDenom) diff --git a/x/evm/keeper/fuzz_test.go b/x/evm/keeper/fuzz_test.go new file mode 100644 index 0000000..891fdfe --- /dev/null +++ b/x/evm/keeper/fuzz_test.go @@ -0,0 +1,92 @@ +package keeper_test + +import ( + "bytes" + "sync" + "sync/atomic" + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" + coretypes "github.com/ethereum/go-ethereum/core/types" + + "github.com/holiman/uint256" + "github.com/stretchr/testify/require" + + "github.com/initia-labs/minievm/x/evm/contracts/counter" + "github.com/initia-labs/minievm/x/evm/types" +) + +func Fuzz_Concurrent_Counter(f *testing.F) { + f.Add(uint8(100), uint8(100)) + f.Fuzz(func(t *testing.T, numThread uint8, numCount uint8) { + if numThread == 0 || numCount == 0 { + t.Skip("skip invalid input") + } + + ctx, input := createDefaultTestInput(t) + _, _, addr := keyPubAddr() + + counterBz, err := hexutil.Decode(counter.CounterBin) + require.NoError(t, err) + + caller := common.BytesToAddress(addr.Bytes()) + retBz, contractAddr, _, err := input.EVMKeeper.EVMCreate(ctx, caller, counterBz, nil, nil) + require.NoError(t, err) + require.NotEmpty(t, retBz) + require.Len(t, contractAddr, 20) + + parsed, err := counter.CounterMetaData.GetAbi() + require.NoError(t, err) + + count := getCount(t, ctx, input, contractAddr) + require.Equal(t, uint256.NewInt(0), count) + + inputBz, err := parsed.Pack("increase_for_fuzz", uint64(numCount)) + require.NoError(t, err) + + atomicBloomBytes := atomic.Pointer[[]byte]{} + atomicBloomBytes.Store(nil) + + var wg sync.WaitGroup + cacheCtxes := make([]sdk.Context, numThread) + for i := uint8(0); i < numThread; i++ { + wg.Add(1) + cacheCtx, _ := ctx.CacheContext() + cacheCtxes[i] = cacheCtx + go func(ctx sdk.Context) { + defer wg.Done() + + // call with value + res, logs, err := input.EVMKeeper.EVMCall(ctx, caller, contractAddr, inputBz, nil, nil) + require.NoError(t, err) + require.Empty(t, res) + bloomBytes := coretypes.LogsBloom(logs.ToEthLogs()) + prev := atomicBloomBytes.Swap(&bloomBytes) + require.True(t, prev == nil || bytes.Equal(*prev, bloomBytes)) + }(cacheCtx) + } + wg.Wait() + + for i := uint8(0); i < numThread; i++ { + count := getCount(t, cacheCtxes[i], input, contractAddr) + require.Equal(t, uint256.NewInt(uint64(numCount)), count) + require.NotEmpty(t, atomicBloomBytes.Load()) + } + }) +} + +func getCount(t *testing.T, ctx sdk.Context, input TestKeepers, contractAddr common.Address) *uint256.Int { + parsed, err := counter.CounterMetaData.GetAbi() + require.NoError(t, err) + + queryInputBz, err := parsed.Pack("count") + require.NoError(t, err) + + queryRes, err := input.EVMKeeper.EVMStaticCall(ctx, types.StdAddress, contractAddr, queryInputBz, nil) + require.NoError(t, err) + + return uint256.NewInt(0).SetBytes32(queryRes) +}