commit 303df79b3b6360f5cfa1207cd48300a6d361d187
parent c76f6a5549df3f071eff5dd2da6c349796bc73fd
Author: lash <dev@holbrook.no>
Date: Mon, 27 Mar 2023 21:30:17 +0100
Simplify offline check
Diffstat:
5 files changed, 57 insertions(+), 31 deletions(-)
diff --git a/python/eth_offline/data/Offline.bin b/python/eth_offline/data/Offline.bin
@@ -1 +1 @@
-608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061136f806100606000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c0100000000000000000000000000000000000000000000000000000000900480631ecc95c8146100795780632c0b80e2146100a95780633327670c146100d9578063602f7c72146100f7578063ce606ee014610127575b600080fd5b610093600480360381019061008e9190610c7e565b610145565b6040516100a09190610d11565b60405180910390f35b6100c360048036038101906100be9190610d8a565b610210565b6040516100d09190610d11565b60405180910390f35b6100e161032f565b6040516100ee9190610dff565b60405180910390f35b610111600480360381019061010c9190610c7e565b610335565b60405161011e9190610d11565b60405180910390f35b61012f6103a2565b60405161013c9190610e29565b60405180910390f35b60006060600080610155866103c6565b92508280519060200120915061016b828661062c565b90503073ffffffffffffffffffffffffffffffffffffffff16632c0b80e282886040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101c4929190610ec3565b602060405180830381865afa1580156101e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102059190610f1f565b935050505092915050565b600061021a610aea565b6102238361069b565b9050600073ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603610294576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028b90610fa9565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff16816000015173ffffffffffffffffffffffffffffffffffffffff16036102d6576000915050610329565b8373ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16149150505b92915050565b60015481565b60006103418383610145565b610380576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037790611015565b60405180910390fd5b6001600081548092919061039390611064565b91905055506001905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606080600080845160166103da91906110ac565b67ffffffffffffffff8111156103f3576103f2610b53565b5b6040519080825280601f01601f1916602001820160405280156104255781602001600182028036833780820191505090505b50925060197f010000000000000000000000000000000000000000000000000000000000000002836000815181106104605761045f6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060029150306c0100000000000000000000000002905060005b6014811015610547578181601481106104c4576104c36110e0565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028484836104f491906110ac565b81518110610505576105046110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061053f90611064565b9150506104a8565b5060148261055591906110ac565b915060005b855181101561062057858181518110610576576105756110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028484836105cd91906110ac565b815181106105de576105dd6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061061890611064565b91505061055a565b50829350505050919050565b60008060008061063b85610a82565b925092509250600186828585604051600081526020016040526040516106649493929190611144565b6020604051602081039080840390855afa158015610686573d6000803e3d6000fd5b50505060206040510351935050505092915050565b6106a3610aea565b606080606060548551146106b957505050610a7d565b601467ffffffffffffffff8111156106d4576106d3610b53565b5b6040519080825280601f01601f1916602001820160405280156107065781602001600182028036833780820191505090505b509250602067ffffffffffffffff81111561072457610723610b53565b5b6040519080825280601f01601f1916602001820160405280156107565781602001600182028036833780820191505090505b509050602067ffffffffffffffff81111561077457610773610b53565b5b6040519080825280601f01601f1916602001820160405280156107a65781602001600182028036833780820191505090505b50915060005b8351811015610867578581815181106107c8576107c76110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002848281518110610825576108246110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061085f90611064565b9150506107ac565b5060005b6020811015610932578560148261088291906110ac565b81518110610893576108926110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382815181106108f0576108ef6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061092a90611064565b91505061086b565b5060005b60208110156109fd578560348261094d91906110ac565b8151811061095e5761095d6110e0565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028282815181106109bb576109ba6110e0565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806109f590611064565b915050610936565b5082610a08906111ea565b6c010000000000000000000000009004846000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505081610a5990611266565b84602001818152505080610a6c90611266565b600190048460400181815250505050505b919050565b60008060006041845114610acb576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610ac290611319565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160008019168152602001600081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610b8b82610b42565b810181811067ffffffffffffffff82111715610baa57610ba9610b53565b5b80604052505050565b6000610bbd610b24565b9050610bc98282610b82565b919050565b600067ffffffffffffffff821115610be957610be8610b53565b5b610bf282610b42565b9050602081019050919050565b82818337600083830152505050565b6000610c21610c1c84610bce565b610bb3565b905082815260208101848484011115610c3d57610c3c610b3d565b5b610c48848285610bff565b509392505050565b600082601f830112610c6557610c64610b38565b5b8135610c75848260208601610c0e565b91505092915050565b60008060408385031215610c9557610c94610b2e565b5b600083013567ffffffffffffffff811115610cb357610cb2610b33565b5b610cbf85828601610c50565b925050602083013567ffffffffffffffff811115610ce057610cdf610b33565b5b610cec85828601610c50565b9150509250929050565b60008115159050919050565b610d0b81610cf6565b82525050565b6000602082019050610d266000830184610d02565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610d5782610d2c565b9050919050565b610d6781610d4c565b8114610d7257600080fd5b50565b600081359050610d8481610d5e565b92915050565b60008060408385031215610da157610da0610b2e565b5b6000610daf85828601610d75565b925050602083013567ffffffffffffffff811115610dd057610dcf610b33565b5b610ddc85828601610c50565b9150509250929050565b6000819050919050565b610df981610de6565b82525050565b6000602082019050610e146000830184610df0565b92915050565b610e2381610d4c565b82525050565b6000602082019050610e3e6000830184610e1a565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610e7e578082015181840152602081019050610e63565b60008484015250505050565b6000610e9582610e44565b610e9f8185610e4f565b9350610eaf818560208601610e60565b610eb881610b42565b840191505092915050565b6000604082019050610ed86000830185610e1a565b8181036020830152610eea8184610e8a565b90509392505050565b610efc81610cf6565b8114610f0757600080fd5b50565b600081519050610f1981610ef3565b92915050565b600060208284031215610f3557610f34610b2e565b5b6000610f4384828501610f0a565b91505092915050565b600082825260208201905092915050565b7f4552525f5a45524f5f56414c494441544f520000000000000000000000000000600082015250565b6000610f93601283610f4c565b9150610f9e82610f5d565b602082019050919050565b60006020820190508181036000830152610fc281610f86565b9050919050565b7f4552525f554e5645524946494544000000000000000000000000000000000000600082015250565b6000610fff600e83610f4c565b915061100a82610fc9565b602082019050919050565b6000602082019050818103600083015261102e81610ff2565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061106f82610de6565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036110a1576110a0611035565b5b600182019050919050565b60006110b782610de6565b91506110c283610de6565b92508282019050808211156110da576110d9611035565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b6111228161110f565b82525050565b600060ff82169050919050565b61113e81611128565b82525050565b60006080820190506111596000830187611119565b6111666020830186611135565b6111736040830185611119565b6111806060830184611119565b95945050505050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b60006111d18251611199565b80915050919050565b60008160020a8302905092915050565b60006111f582610e44565b826111ff84611189565b905061120a816111c5565b9250601482101561124a576112457fffffffffffffffffffffffffffffffffffffffff000000000000000000000000836014036008026111da565b831692505b5050919050565b600061125d825161110f565b80915050919050565b600061127182610e44565b8261127b84611189565b905061128681611251565b925060208210156112c6576112c17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026111da565b831692505b5050919050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000611303601883610f4c565b915061130e826112cd565b602082019050919050565b60006020820190508181036000830152611332816112f6565b905091905056fea2646970667358221220576355ede34468649e9d1e13afcc70737420597631fedabefd3accf551f2acb664736f6c63430008130033
-\ No newline at end of file
+608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610e2f806100606000396000f3fe608060405234801561001057600080fd5b5060043610610074576000357c0100000000000000000000000000000000000000000000000000000000900480631ecc95c8146100795780632c0b80e2146100a95780633327670c146100d9578063602f7c72146100f7578063ce606ee014610127575b600080fd5b610093600480360381019061008e9190610826565b610145565b6040516100a091906108b9565b60405180910390f35b6100c360048036038101906100be9190610932565b610210565b6040516100d091906108b9565b60405180910390f35b6100e16102f8565b6040516100ee91906109a7565b60405180910390f35b610111600480360381019061010c9190610826565b6102fe565b60405161011e91906109a7565b60405180910390f35b61012f61036b565b60405161013c91906109d1565b60405180910390f35b600060606000806101558661038f565b92508280519060200120915061016b82866105f5565b90503073ffffffffffffffffffffffffffffffffffffffff16632c0b80e282886040518363ffffffff167c01000000000000000000000000000000000000000000000000000000000281526004016101c4929190610a6b565b602060405180830381865afa1580156101e1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102059190610ac7565b935050505092915050565b60008073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361024e57600090506102f2565b60008261025a90610b55565b7401000000000000000000000000000000000000000090046bffffffffffffffffffffffff160361028e57600090506102f2565b60608251146102a057600090506102f2565b8273ffffffffffffffffffffffffffffffffffffffff1660008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161490505b92915050565b60015481565b600061030a8383610145565b610349576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161034090610c19565b60405180910390fd5b6001600081548092919061035c90610c68565b91905055506000905092915050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b606080600080845160166103a39190610cb0565b67ffffffffffffffff8111156103bc576103bb6106fb565b5b6040519080825280601f01601f1916602001820160405280156103ee5781602001600182028036833780820191505090505b50925060197f0100000000000000000000000000000000000000000000000000000000000000028360008151811061042957610428610ce4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060029150306c0100000000000000000000000002905060005b60148110156105105781816014811061048d5761048c610ce4565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028484836104bd9190610cb0565b815181106104ce576104cd610ce4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061050890610c68565b915050610471565b5060148261051e9190610cb0565b915060005b85518110156105e95785818151811061053f5761053e610ce4565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028484836105969190610cb0565b815181106105a7576105a6610ce4565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806105e190610c68565b915050610523565b50829350505050919050565b60008060008061060485610664565b9250925092506001868285856040516000815260200160405260405161062d9493929190610d48565b6020604051602081039080840390855afa15801561064f573d6000803e3d6000fd5b50505060206040510351935050505092915050565b600080600060418451146106ad576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106a490610dd9565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610733826106ea565b810181811067ffffffffffffffff82111715610752576107516106fb565b5b80604052505050565b60006107656106cc565b9050610771828261072a565b919050565b600067ffffffffffffffff821115610791576107906106fb565b5b61079a826106ea565b9050602081019050919050565b82818337600083830152505050565b60006107c96107c484610776565b61075b565b9050828152602081018484840111156107e5576107e46106e5565b5b6107f08482856107a7565b509392505050565b600082601f83011261080d5761080c6106e0565b5b813561081d8482602086016107b6565b91505092915050565b6000806040838503121561083d5761083c6106d6565b5b600083013567ffffffffffffffff81111561085b5761085a6106db565b5b610867858286016107f8565b925050602083013567ffffffffffffffff811115610888576108876106db565b5b610894858286016107f8565b9150509250929050565b60008115159050919050565b6108b38161089e565b82525050565b60006020820190506108ce60008301846108aa565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006108ff826108d4565b9050919050565b61090f816108f4565b811461091a57600080fd5b50565b60008135905061092c81610906565b92915050565b60008060408385031215610949576109486106d6565b5b60006109578582860161091d565b925050602083013567ffffffffffffffff811115610978576109776106db565b5b610984858286016107f8565b9150509250929050565b6000819050919050565b6109a18161098e565b82525050565b60006020820190506109bc6000830184610998565b92915050565b6109cb816108f4565b82525050565b60006020820190506109e660008301846109c2565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610a26578082015181840152602081019050610a0b565b60008484015250505050565b6000610a3d826109ec565b610a4781856109f7565b9350610a57818560208601610a08565b610a60816106ea565b840191505092915050565b6000604082019050610a8060008301856109c2565b8181036020830152610a928184610a32565b90509392505050565b610aa48161089e565b8114610aaf57600080fd5b50565b600081519050610ac181610a9b565b92915050565b600060208284031215610add57610adc6106d6565b5b6000610aeb84828501610ab2565b91505092915050565b6000819050602082019050919050565b60007fffffffffffffffffffffffff000000000000000000000000000000000000000082169050919050565b6000610b3c8251610b04565b80915050919050565b60008160020a8302905092915050565b6000610b60826109ec565b82610b6a84610af4565b9050610b7581610b30565b9250600c821015610bb557610bb07fffffffffffffffffffffffff000000000000000000000000000000000000000083600c03600802610b45565b831692505b5050919050565b600082825260208201905092915050565b7f4552525f554e5645524946494544000000000000000000000000000000000000600082015250565b6000610c03600e83610bbc565b9150610c0e82610bcd565b602082019050919050565b60006020820190508181036000830152610c3281610bf6565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610c738261098e565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610ca557610ca4610c39565b5b600182019050919050565b6000610cbb8261098e565b9150610cc68361098e565b9250828201905080821115610cde57610cdd610c39565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000819050919050565b610d2681610d13565b82525050565b600060ff82169050919050565b610d4281610d2c565b82525050565b6000608082019050610d5d6000830187610d1d565b610d6a6020830186610d39565b610d776040830185610d1d565b610d846060830184610d1d565b95945050505050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000610dc3601883610bbc565b9150610dce82610d8d565b602082019050919050565b60006020820190508181036000830152610df281610db6565b905091905056fea2646970667358221220a6507aa34b62bae066116d9284c60596eab1ef5a189481fdd7c617f6052f928d64736f6c63430008130033
+\ No newline at end of file
diff --git a/python/eth_offline/data/Offline.json b/python/eth_offline/data/Offline.json
@@ -1 +1 @@
-[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"contractOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"executeOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"executedTimes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_validator","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"isOfflineValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
+[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"contractOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"executeOfflineRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"executedTimes","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"isOfflineValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyOfflineRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]
diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py
@@ -54,6 +54,7 @@ class TestOfflineEth(EthTesterCase):
def test_validator(self):
+ n = os.urandom(12)
c = TxFactory(self.chain_spec)
j = JSONRPCRequest()
o = j.template()
@@ -63,7 +64,7 @@ class TestOfflineEth(EthTesterCase):
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[0]))
- enc.bytes(strip_0x(self.accounts[1]) + '666f6f')
+ enc.bytes(n.hex() + strip_0x(self.accounts[1]) + '666f6f')
data = add_0x(enc.get())
tx = c.template(self.accounts[0], self.address)
tx = c.set_code(tx, data)
@@ -83,18 +84,17 @@ class TestOfflineEth(EthTesterCase):
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[2]))
- enc.bytes(strip_0x(self.accounts[1]) + v.hex())
+ enc.bytes(n.hex() + strip_0x(self.accounts[1]) + v.hex())
data = add_0x(enc.get())
tx = c.template(self.accounts[0], self.address)
tx = c.set_code(tx, data)
o['params'].append(c.normalize(tx))
o['params'].append('latest')
o = j.finalize(o)
-
r = self.rpc.do(o)
- r = strip_0x(r)
self.assertEqual(int(r, 16), 0)
+ n = b'\x00' * 12
c = TxFactory(self.chain_spec)
j = JSONRPCRequest()
o = j.template()
@@ -104,14 +104,33 @@ class TestOfflineEth(EthTesterCase):
enc.typ(ABIContractType.ADDRESS)
enc.typ(ABIContractType.BYTES)
enc.address(strip_0x(self.accounts[0]))
- enc.bytes(strip_0x(self.accounts[1]) + v.hex())
+ enc.bytes(n.hex() + strip_0x(self.accounts[1]) + v.hex())
data = add_0x(enc.get())
tx = c.template(self.accounts[0], self.address)
tx = c.set_code(tx, data)
o['params'].append(c.normalize(tx))
o['params'].append('latest')
o = j.finalize(o)
+ r = self.rpc.do(o)
+ self.assertEqual(int(r, 16), 0)
+ n = os.urandom(12)
+ c = TxFactory(self.chain_spec)
+ j = JSONRPCRequest()
+ o = j.template()
+ o['method'] = 'eth_call'
+ enc = ABIContractEncoder()
+ enc.method('isOfflineValid')
+ enc.typ(ABIContractType.ADDRESS)
+ enc.typ(ABIContractType.BYTES)
+ enc.address(strip_0x(self.accounts[0]))
+ enc.bytes(n.hex() + strip_0x(self.accounts[1]) + v.hex())
+ data = add_0x(enc.get())
+ tx = c.template(self.accounts[0], self.address)
+ tx = c.set_code(tx, data)
+ o['params'].append(c.normalize(tx))
+ o['params'].append('latest')
+ o = j.finalize(o)
r = self.rpc.do(o)
r = strip_0x(r)
self.assertEqual(int(r, 16), 1)
@@ -119,8 +138,9 @@ class TestOfflineEth(EthTesterCase):
def test_ok_verify(self):
beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2]))
+ msg_nonce = os.urandom(12)
msg_bin = os.urandom(64)
- msg_data = beneficiary_bin + msg_bin
+ msg_data = msg_nonce + beneficiary_bin + msg_bin
sig = self.signer.sign_validator_message(self.accounts[0], self.address, msg_data)
sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big')
@@ -143,6 +163,7 @@ class TestOfflineEth(EthTesterCase):
o['params'].append('latest')
o = j.finalize(o)
+
r = self.rpc.do(o)
r = strip_0x(r)
@@ -151,8 +172,9 @@ class TestOfflineEth(EthTesterCase):
def test_verify_fail_owner(self):
beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2]))
+ msg_nonce = os.urandom(12)
msg_bin = os.urandom(64)
- msg_data = beneficiary_bin + msg_bin
+ msg_data = msg_nonce + beneficiary_bin + msg_bin
sig = self.signer.sign_validator_message(self.accounts[1], self.address, msg_data)
sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big')
@@ -174,17 +196,15 @@ class TestOfflineEth(EthTesterCase):
o['params'].append(c.normalize(tx))
o['params'].append('latest')
o = j.finalize(o)
-
r = self.rpc.do(o)
- r = strip_0x(r)
-
self.assertEqual(int(r, 16), 0)
-
+
def test_execute(self):
beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2]))
+ msg_nonce = os.urandom(12)
msg_bin = os.urandom(64)
- msg_data = beneficiary_bin + msg_bin
+ msg_data = msg_nonce + beneficiary_bin + msg_bin
sig = self.signer.sign_validator_message(self.accounts[0], self.address, msg_data)
sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big')
diff --git a/solidity/Offline.sol b/solidity/Offline.sol
@@ -7,6 +7,7 @@ import './OfflineBase.sol';
contract OfflineRubber is Offline {
struct Instruction {
+ bytes12 nonce;
address beneficiary;
bytes32 domain;
uint256 value;
@@ -19,27 +20,27 @@ contract OfflineRubber is Offline {
contractOwner = msg.sender;
}
- function executeOfflineRequest(bytes memory _data, bytes memory _signature) public override returns(bool) {
+ function executeOfflineRequest(bytes memory _data, bytes memory _signature) public override returns(uint256) {
require(verifyOfflineRequest(_data, _signature), 'ERR_UNVERIFIED');
executedTimes++;
- return true;
+ return 0;
}
- function isOfflineValid(address _validator, bytes memory _data) external override view returns(bool) {
- Instruction memory instruction;
-
- instruction = splitData(_data);
-
- require(_validator != address(0), 'ERR_ZERO_VALIDATOR');
-
- if (instruction.beneficiary == address(0)) {
+ function isOfflineValid(address _signer, bytes memory _data) external override view returns(bool) {
+ if (_signer == address(0)) {
return false;
}
-
- return contractOwner == _validator;
+ if (uint96(bytes12(_data)) == 0) {
+ return false;
+ }
+ if (_data.length != 96) {
+ return false;
+ }
+ return contractOwner == _signer;
}
function splitData(bytes memory _data) private pure returns(Instruction memory instruction) {
+ bytes memory nonce;
bytes memory beneficiary;
bytes memory domain;
bytes memory value;
@@ -48,19 +49,24 @@ contract OfflineRubber is Offline {
return instruction;
}
+ nonce = new bytes(12);
beneficiary = new bytes(20);
value = new bytes(32);
domain = new bytes(32);
+ for (uint256 i; i < nonce.length; i++) {
+ nonce[i] = _data[i];
+ }
for (uint256 i; i < beneficiary.length; i++) {
- beneficiary[i] = _data[i];
+ beneficiary[i] = _data[i+12];
}
for (uint256 i; i < 32; i++) {
- domain[i] = _data[i + 20];
+ domain[i] = _data[i + 32];
}
for (uint256 i; i < 32; i++) {
- value[i] = _data[i + 52];
+ value[i] = _data[i + 64];
}
+ instruction.nonce = bytes12(nonce);
instruction.beneficiary = address(bytes20(beneficiary));
instruction.domain = bytes32(domain);
instruction.value = uint256(bytes32(value));
diff --git a/solidity/OfflineBase.sol b/solidity/OfflineBase.sol
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
// Some methods are copied under other licenses, please see code comments for details
abstract contract Offline {
- function executeOfflineRequest(bytes memory _data, bytes memory _signature) public virtual returns(bool);
+ function executeOfflineRequest(bytes memory _data, bytes memory _signature) public virtual returns(uint256);
function isOfflineValid(address _validator, bytes memory _data) external virtual view returns(bool);