eth-offline

EVM token minter frontend for offline issuance using ERC712 structured signatures.
Log | Files | Refs

commit e9701a5eb5ab68d65eca2c6d57cc42ff1ce07335
parent 64fe7e25287bc3fcdbf4a575faf8c8faa83f42e0
Author: lash <dev@holbrook.no>
Date:   Mon, 27 Mar 2023 14:25:54 +0100

Add structured instruction as signed payload

Diffstat:
Mpython/eth_offline/data/Offline.bin | 4++--
Mpython/eth_offline/data/Offline.json | 2+-
Mpython/tests/test_basic.py | 31+++++++++++++++++++++++++------
Msolidity/Offline.sol | 34+++++++++++++++++++++-------------
Msolidity/OfflineBase.sol | 8++++++--
5 files changed, 55 insertions(+), 24 deletions(-)

diff --git a/python/eth_offline/data/Offline.bin b/python/eth_offline/data/Offline.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061157e806100606000396000f3fe608060405234801561001057600080fd5b50600436106100b0576000357c010000000000000000000000000000000000000000000000000000000090048063a7bb580311610083578063a7bb580314610150578063aa1d23a014610182578063aeb02492146101b2578063ca9bc523146101e2578063e939567914610212576100b0565b8063557ba855146100b5578063772295f6146100d15780638da5cb5b1461010257806397aba7f914610120575b600080fd5b6100cf60048036038101906100ca9190610dd2565b610242565b005b6100eb60048036038101906100e69190610dd2565b610245565b6040516100f9929190610edb565b60405180910390f35b61010a6104f5565b6040516101179190610f0b565b60405180910390f35b61013a60048036038101906101359190610f5c565b61051e565b6040516101479190610f0b565b60405180910390f35b61016a60048036038101906101659190610dd2565b61058d565b60405161017993929190610fe3565b60405180910390f35b61019c6004803603810190610197919061101a565b6105f5565b6040516101a99190610f0b565b60405180910390f35b6101cc60048036038101906101c7919061101a565b610623565b6040516101d991906110ad565b60405180910390f35b6101fc60048036038101906101f79190610dd2565b610671565b60405161020991906110c8565b60405180910390f35b61022c60048036038101906102279190611120565b610a3f565b60405161023991906111a2565b60405180910390f35b50565b600060608060606014855111610290576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028790611210565b60405180910390fd5b601467ffffffffffffffff8111156102ab576102aa610ca7565b5b6040519080825280601f01601f1916602001820160405280156102dd5781602001600182028036833780820191505090505b509150601485516102ee919061125f565b67ffffffffffffffff81111561030757610306610ca7565b5b6040519080825280601f01601f1916602001820160405280156103395781602001600182028036833780820191505090505b50905060005b82518110156103fa5785818151811061035b5761035a611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382815181106103b8576103b7611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806103f2906112c2565b91505061033f565b5060005b81518110156104c55785601482610415919061130a565b8151811061042657610425611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000282828151811061048357610482611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806104bd906112c2565b9150506103fe565b506104cf81610242565b816104d99061139f565b6c01000000000000000000000000900481935093505050915091565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060008061052d8561058d565b925092509250600186828585604051600081526020016040526040516105569493929190611406565b6020604051602081039080840390855afa158015610578573d6000803e3d6000fd5b50505060206040510351935050505092915050565b600080600060418451146105d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105cd90611497565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b600080606061060385610671565b905080805190602001209150610619828561051e565b9250505092915050565b60008061062e6104f5565b905061063a84846105f5565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161491505092915050565b6060806000606060008060006014885161068b919061130a565b945061069685610a3f565b9350835192508483601a6106aa919061130a565b6106b4919061130a565b67ffffffffffffffff8111156106cd576106cc610ca7565b5b6040519080825280601f01601f1916602001820160405280156106ff5781602001600182028036833780820191505090505b50955060005b601a8110156107bc577919457468657265756d205369676e6564204d6573736167653a0a66010000000000000281601a811061074457610743611293565b5b1a7f01000000000000000000000000000000000000000000000000000000000000000287828151811061077a57610779611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806107b4906112c2565b915050610705565b50601a826107ca919061130a565b915060005b83811015610894578481815181106107ea576107e9611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002878483610841919061130a565b8151811061085257610851611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061088c906112c2565b9150506107cf565b5082826108a1919061130a565b9150306c0100000000000000000000000002905060005b6014811015610957578181601481106108d4576108d3611293565b5b1a7f010000000000000000000000000000000000000000000000000000000000000002878483610904919061130a565b8151811061091557610914611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061094f906112c2565b9150506108b8565b50601482610965919061130a565b915060005b8851811015610a305788818151811061098657610985611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028784836109dd919061130a565b815181106109ee576109ed611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610a28906112c2565b91505061096a565b50859650505050505050919050565b606060006064905060008167ffffffffffffffff811115610a6357610a62610ca7565b5b6040519080825280601f01601f191660200182016040528015610a955781602001600182028036833780820191505090505b50905060005b60008514610b46576000600a86610ab291906114e6565b9050600a86610ac19190611517565b9550806030610ad0919061130a565b7f010000000000000000000000000000000000000000000000000000000000000002838380610afe906112c2565b945081518110610b1157610b10611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050610a9b565b60008167ffffffffffffffff811115610b6257610b61610ca7565b5b6040519080825280601f01601f191660200182016040528015610b945781602001600182028036833780820191505090505b50905060005b82811015610c6b578381600185610bb1919061125f565b610bbb919061125f565b81518110610bcc57610bcb611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002828281518110610c2957610c28611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610c63906112c2565b915050610b9a565b5080945050505050919050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610cdf82610c96565b810181811067ffffffffffffffff82111715610cfe57610cfd610ca7565b5b80604052505050565b6000610d11610c78565b9050610d1d8282610cd6565b919050565b600067ffffffffffffffff821115610d3d57610d3c610ca7565b5b610d4682610c96565b9050602081019050919050565b82818337600083830152505050565b6000610d75610d7084610d22565b610d07565b905082815260208101848484011115610d9157610d90610c91565b5b610d9c848285610d53565b509392505050565b600082601f830112610db957610db8610c8c565b5b8135610dc9848260208601610d62565b91505092915050565b600060208284031215610de857610de7610c82565b5b600082013567ffffffffffffffff811115610e0657610e05610c87565b5b610e1284828501610da4565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610e4682610e1b565b9050919050565b610e5681610e3b565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610e96578082015181840152602081019050610e7b565b60008484015250505050565b6000610ead82610e5c565b610eb78185610e67565b9350610ec7818560208601610e78565b610ed081610c96565b840191505092915050565b6000604082019050610ef06000830185610e4d565b8181036020830152610f028184610ea2565b90509392505050565b6000602082019050610f206000830184610e4d565b92915050565b6000819050919050565b610f3981610f26565b8114610f4457600080fd5b50565b600081359050610f5681610f30565b92915050565b60008060408385031215610f7357610f72610c82565b5b6000610f8185828601610f47565b925050602083013567ffffffffffffffff811115610fa257610fa1610c87565b5b610fae85828601610da4565b9150509250929050565b610fc181610f26565b82525050565b600060ff82169050919050565b610fdd81610fc7565b82525050565b6000606082019050610ff86000830186610fb8565b6110056020830185610fb8565b6110126040830184610fd4565b949350505050565b6000806040838503121561103157611030610c82565b5b600083013567ffffffffffffffff81111561104f5761104e610c87565b5b61105b85828601610da4565b925050602083013567ffffffffffffffff81111561107c5761107b610c87565b5b61108885828601610da4565b9150509250929050565b60008115159050919050565b6110a781611092565b82525050565b60006020820190506110c2600083018461109e565b92915050565b600060208201905081810360008301526110e28184610ea2565b905092915050565b6000819050919050565b6110fd816110ea565b811461110857600080fd5b50565b60008135905061111a816110f4565b92915050565b60006020828403121561113657611135610c82565b5b60006111448482850161110b565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60006111748261114d565b61117e8185611158565b935061118e818560208601610e78565b61119781610c96565b840191505092915050565b600060208201905081810360008301526111bc8184611169565b905092915050565b7f4552525f434f4e54454e54530000000000000000000000000000000000000000600082015250565b60006111fa600c83611158565b9150611205826111c4565b602082019050919050565b60006020820190508181036000830152611229816111ed565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061126a826110ea565b9150611275836110ea565b925082820390508181111561128d5761128c611230565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006112cd826110ea565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036112ff576112fe611230565b5b600182019050919050565b6000611315826110ea565b9150611320836110ea565b925082820190508082111561133857611337611230565b5b92915050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b6000611386825161134e565b80915050919050565b60008160020a8302905092915050565b60006113aa82610e5c565b826113b48461133e565b90506113bf8161137a565b925060148210156113ff576113fa7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008360140360080261138f565b831692505b5050919050565b600060808201905061141b6000830187610fb8565b6114286020830186610fd4565b6114356040830185610fb8565b6114426060830184610fb8565b95945050505050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000611481601883611158565b915061148c8261144b565b602082019050919050565b600060208201905081810360008301526114b081611474565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006114f1826110ea565b91506114fc836110ea565b92508261150c5761150b6114b7565b5b828206905092915050565b6000611522826110ea565b915061152d836110ea565b92508261153d5761153c6114b7565b5b82820490509291505056fea2646970667358221220188593ee01bbc2e2f184913703fe5e7a903129044a2017658dfaef16b2f12a7864736f6c63430008120033 -\ No newline at end of file +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506117cc806100606000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c010000000000000000000000000000000000000000000000000000000090048063aa1d23a011610078578063aa1d23a01461015a578063aeb024921461018a578063ca9bc523146101ba578063e9395679146101ea576100a5565b8063772295f6146100aa5780638da5cb5b146100da57806397aba7f9146100f8578063a7bb580314610128575b600080fd5b6100c460048036038101906100bf9190610f4a565b61021a565b6040516100d19190611048565b60405180910390f35b6100e2610633565b6040516100ef9190611072565b60405180910390f35b610112600480360381019061010d91906110b9565b61065c565b60405161011f9190611072565b60405180910390f35b610142600480360381019061013d9190610f4a565b6106cb565b60405161015193929190611140565b60405180910390f35b610174600480360381019061016f9190611177565b610733565b6040516101819190611072565b60405180910390f35b6101a4600480360381019061019f9190611177565b610761565b6040516101b1919061120a565b60405180910390f35b6101d460048036038101906101cf9190610f4a565b6107af565b6040516101e191906112a4565b60405180910390f35b61020460048036038101906101ff91906112f2565b610b7d565b6040516102119190611374565b60405180910390f35b610222610db6565b6060806060605485511461026b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610262906113e2565b60405180910390fd5b601467ffffffffffffffff81111561028657610285610e1f565b5b6040519080825280601f01601f1916602001820160405280156102b85781602001600182028036833780820191505090505b509250602067ffffffffffffffff8111156102d6576102d5610e1f565b5b6040519080825280601f01601f1916602001820160405280156103085781602001600182028036833780820191505090505b509050602067ffffffffffffffff81111561032657610325610e1f565b5b6040519080825280601f01601f1916602001820160405280156103585781602001600182028036833780820191505090505b50915060005b83518110156104195785818151811061037a57610379611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028482815181106103d7576103d6611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061041190611460565b91505061035e565b5060005b60208110156104e4578560148261043491906114a8565b8151811061044557610444611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382815181106104a2576104a1611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806104dc90611460565b91505061041d565b5060005b60208110156105af57856034826104ff91906114a8565b815181106105105761050f611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000282828151811061056d5761056c611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806105a790611460565b9150506104e8565b50826105ba9061153d565b6c010000000000000000000000009004846000019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508161060b906115b9565b8460200181815250508061061e906115b9565b60019004846040018181525050505050919050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060008061066b856106cb565b925092509250600186828585604051600081526020016040526040516106949493929190611620565b6020604051602081039080840390855afa1580156106b6573d6000803e3d6000fd5b50505060206040510351935050505092915050565b60008060006041845114610714576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161070b906116b1565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b6000806060610741856107af565b905080805190602001209150610757828561065c565b9250505092915050565b60008061076c610633565b90506107788484610733565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161491505092915050565b606080600060606000806000601488516107c991906114a8565b94506107d485610b7d565b9350835192508483601a6107e891906114a8565b6107f291906114a8565b67ffffffffffffffff81111561080b5761080a610e1f565b5b6040519080825280601f01601f19166020018201604052801561083d5781602001600182028036833780820191505090505b50955060005b601a8110156108fa577919457468657265756d205369676e6564204d6573736167653a0a66010000000000000281601a811061088257610881611402565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028782815181106108b8576108b7611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806108f290611460565b915050610843565b50601a8261090891906114a8565b915060005b838110156109d25784818151811061092857610927611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000287848361097f91906114a8565b815181106109905761098f611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806109ca90611460565b91505061090d565b5082826109df91906114a8565b9150306c0100000000000000000000000002905060005b6014811015610a9557818160148110610a1257610a11611402565b5b1a7f010000000000000000000000000000000000000000000000000000000000000002878483610a4291906114a8565b81518110610a5357610a52611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610a8d90611460565b9150506109f6565b50601482610aa391906114a8565b915060005b8851811015610b6e57888181518110610ac457610ac3611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002878483610b1b91906114a8565b81518110610b2c57610b2b611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610b6690611460565b915050610aa8565b50859650505050505050919050565b606060006064905060008167ffffffffffffffff811115610ba157610ba0610e1f565b5b6040519080825280601f01601f191660200182016040528015610bd35781602001600182028036833780820191505090505b50905060005b60008514610c84576000600a86610bf09190611700565b9050600a86610bff9190611731565b9550806030610c0e91906114a8565b7f010000000000000000000000000000000000000000000000000000000000000002838380610c3c90611460565b945081518110610c4f57610c4e611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050610bd9565b60008167ffffffffffffffff811115610ca057610c9f610e1f565b5b6040519080825280601f01601f191660200182016040528015610cd25781602001600182028036833780820191505090505b50905060005b82811015610da9578381600185610cef9190611762565b610cf99190611762565b81518110610d0a57610d09611402565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002828281518110610d6757610d66611402565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610da190611460565b915050610cd8565b5080945050505050919050565b6040518060600160405280600073ffffffffffffffffffffffffffffffffffffffff16815260200160008019168152602001600081525090565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610e5782610e0e565b810181811067ffffffffffffffff82111715610e7657610e75610e1f565b5b80604052505050565b6000610e89610df0565b9050610e958282610e4e565b919050565b600067ffffffffffffffff821115610eb557610eb4610e1f565b5b610ebe82610e0e565b9050602081019050919050565b82818337600083830152505050565b6000610eed610ee884610e9a565b610e7f565b905082815260208101848484011115610f0957610f08610e09565b5b610f14848285610ecb565b509392505050565b600082601f830112610f3157610f30610e04565b5b8135610f41848260208601610eda565b91505092915050565b600060208284031215610f6057610f5f610dfa565b5b600082013567ffffffffffffffff811115610f7e57610f7d610dff565b5b610f8a84828501610f1c565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610fbe82610f93565b9050919050565b610fce81610fb3565b82525050565b6000819050919050565b610fe781610fd4565b82525050565b6000819050919050565b61100081610fed565b82525050565b60608201600082015161101c6000850182610fc5565b50602082015161102f6020850182610fde565b5060408201516110426040850182610ff7565b50505050565b600060608201905061105d6000830184611006565b92915050565b61106c81610fb3565b82525050565b60006020820190506110876000830184611063565b92915050565b61109681610fd4565b81146110a157600080fd5b50565b6000813590506110b38161108d565b92915050565b600080604083850312156110d0576110cf610dfa565b5b60006110de858286016110a4565b925050602083013567ffffffffffffffff8111156110ff576110fe610dff565b5b61110b85828601610f1c565b9150509250929050565b61111e81610fd4565b82525050565b600060ff82169050919050565b61113a81611124565b82525050565b60006060820190506111556000830186611115565b6111626020830185611115565b61116f6040830184611131565b949350505050565b6000806040838503121561118e5761118d610dfa565b5b600083013567ffffffffffffffff8111156111ac576111ab610dff565b5b6111b885828601610f1c565b925050602083013567ffffffffffffffff8111156111d9576111d8610dff565b5b6111e585828601610f1c565b9150509250929050565b60008115159050919050565b611204816111ef565b82525050565b600060208201905061121f60008301846111fb565b92915050565b600081519050919050565b600082825260208201905092915050565b60005b8381101561125f578082015181840152602081019050611244565b60008484015250505050565b600061127682611225565b6112808185611230565b9350611290818560208601611241565b61129981610e0e565b840191505092915050565b600060208201905081810360008301526112be818461126b565b905092915050565b6112cf81610fed565b81146112da57600080fd5b50565b6000813590506112ec816112c6565b92915050565b60006020828403121561130857611307610dfa565b5b6000611316848285016112dd565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60006113468261131f565b611350818561132a565b9350611360818560208601611241565b61136981610e0e565b840191505092915050565b6000602082019050818103600083015261138e818461133b565b905092915050565b7f4552525f434f4e54454e545f4c454e4754480000000000000000000000000000600082015250565b60006113cc60128361132a565b91506113d782611396565b602082019050919050565b600060208201905081810360008301526113fb816113bf565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061146b82610fed565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361149d5761149c611431565b5b600182019050919050565b60006114b382610fed565b91506114be83610fed565b92508282019050808211156114d6576114d5611431565b5b92915050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b600061152482516114ec565b80915050919050565b60008160020a8302905092915050565b600061154882611225565b82611552846114dc565b905061155d81611518565b9250601482101561159d576115987fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008360140360080261152d565b831692505b5050919050565b60006115b08251610fd4565b80915050919050565b60006115c482611225565b826115ce846114dc565b90506115d9816115a4565b92506020821015611619576116147fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8360200360080261152d565b831692505b5050919050565b60006080820190506116356000830187611115565b6116426020830186611131565b61164f6040830185611115565b61165c6060830184611115565b95945050505050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b600061169b60188361132a565b91506116a682611665565b602082019050919050565b600060208201905081810360008301526116ca8161168e565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061170b82610fed565b915061171683610fed565b925082611726576117256116d1565b5b828206905092915050565b600061173c82610fed565b915061174783610fed565b925082611757576117566116d1565b5b828204905092915050565b600061176d82610fed565b915061177883610fed565b92508282039050818111156117905761178f611431565b5b9291505056fea264697066735822122084bc85cf55426925107b0b89627a80a189fbfa1975d1e00abeaf5cb672034ed164736f6c63430008120033 +\ 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":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"fromRequest","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_ethSignedMessageHash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"recoverSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"splitData","outputs":[{"internalType":"address","name":"_beneficiary","type":"address"},{"internalType":"bytes","name":"_extra","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"splitSignature","outputs":[{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint8","name":"v","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"toRequest","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"v","type":"uint256"}],"name":"uintToString","outputs":[{"internalType":"string","name":"str","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"verifyExtraData","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}] +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"fromRequest","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_ethSignedMessageHash","type":"bytes32"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"recoverSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"splitData","outputs":[{"components":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"uint256","name":"value","type":"uint256"}],"internalType":"struct OfflineRubber.Instruction","name":"instruction","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"sig","type":"bytes"}],"name":"splitSignature","outputs":[{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint8","name":"v","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"toRequest","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"v","type":"uint256"}],"name":"uintToString","outputs":[{"internalType":"string","name":"str","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"verifyRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}] diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py @@ -15,10 +15,11 @@ from chainlib.eth.gas import OverrideGasOracle from chainlib.eth.contract import ABIContractEncoder from chainlib.eth.contract import ABIContractType from chainlib.jsonrpc import JSONRPCRequest +from chainlib.error import JSONRPCException from hexathon import add_0x from hexathon import strip_0x from hexathon import same as same_hex -from funga.eth.message import to_digest +from funga.eth.message import to_personal_message script_dir = os.path.realpath(os.path.dirname(__file__)) data_dir = os.path.join(script_dir, '..', 'eth_offline', 'data') @@ -67,19 +68,39 @@ class TestOfflineEth(EthTesterCase): o['params'].append('latest') o = j.finalize(o) + with self.assertRaises(JSONRPCException): + self.rpc.do(o) + + v = os.urandom(64) + c = TxFactory(self.chain_spec) + j = JSONRPCRequest() + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('splitData') + enc.typ(ABIContractType.BYTES) + enc.bytes(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.assertTrue(same_hex(r[24:64], self.accounts[1])) - self.assertTrue(same_hex(r[192:198], '666f6f')) - + self.assertTrue(same_hex(r[64:128], v[:32].hex())) + self.assertTrue(same_hex(r[128:192], v[32:].hex())) + def test_sign_match(self): contract_bin = bytes.fromhex(strip_0x(self.address)) beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) msg_bin = b'foo' msg_data = beneficiary_bin + msg_bin msg_tosign = contract_bin + msg_data - msg_digest = to_digest(msg_tosign) + msg_digest = to_personal_message(msg_tosign, digest=True) sig = self.signer.sign_ethereum_message(self.accounts[1], msg_tosign) sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big') @@ -91,7 +112,6 @@ class TestOfflineEth(EthTesterCase): o['method'] = 'eth_call' enc = ABIContractEncoder() enc.method('recoverSigner') - #enc.typ(ABIContractType.BYTES) enc.typ(ABIContractType.BYTES32) enc.typ(ABIContractType.BYTES) enc.bytes32(msg_digest.hex()) @@ -213,7 +233,6 @@ class TestOfflineEth(EthTesterCase): self.assertEqual(int(r, 16), 1) - def test_verify_fail_owner(self): contract_bin = bytes.fromhex(strip_0x(self.address)) beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) diff --git a/solidity/Offline.sol b/solidity/Offline.sol @@ -1,41 +1,49 @@ pragma solidity ^0.8.0; -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: AGPL-3.0-or-later import './OfflineBase.sol'; contract OfflineRubber is Offline { + struct Instruction { + address beneficiary; + bytes32 domain; + uint256 value; + } + address contractOwner; constructor() { contractOwner = msg.sender; } - function verifyExtraData(bytes memory _data) public override pure { - _data; - } - function owner() public override view returns(address) { return contractOwner; } - function splitData(bytes memory _data) public pure returns(address _beneficiary, bytes memory _extra) { + function splitData(bytes memory _data) public pure returns(Instruction memory instruction) { bytes memory beneficiary; - bytes memory extra; + bytes memory domain; + bytes memory value; - require(_data.length > 20, 'ERR_CONTENTS'); + require(_data.length == 84, 'ERR_CONTENT_LENGTH'); beneficiary = new bytes(20); - extra = new bytes(_data.length - 20); + value = new bytes(32); + domain = new bytes(32); for (uint256 i; i < beneficiary.length; i++) { beneficiary[i] = _data[i]; } - for (uint256 i; i < extra.length; i++) { - extra[i] = _data[i+20]; + for (uint256 i; i < 32; i++) { + domain[i] = _data[i + 20]; + } + for (uint256 i; i < 32; i++) { + value[i] = _data[i + 52]; } - verifyExtraData(extra); - return (address(bytes20(beneficiary)), extra); + instruction.beneficiary = address(bytes20(beneficiary)); + instruction.domain = bytes32(domain); + instruction.value = uint256(bytes32(value)); } } diff --git a/solidity/OfflineBase.sol b/solidity/OfflineBase.sol @@ -1,9 +1,11 @@ pragma solidity ^0.8.0; -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: AGPL-3.0-or-later +// Some methods are copied under other licenses, please see code comments for details abstract contract Offline { + // ERC191 - Ethereum Signed Message bytes26 constant prefix = bytes26(0x19457468657265756d205369676e6564204d6573736167653a0a); function fromRequest(bytes memory _data, bytes memory _signature) public view returns(address) { @@ -59,7 +61,7 @@ abstract contract Offline { return message; } - function verifyExtraData(bytes memory _data) public virtual pure; + //function verifyExtraData(bytes memory _data) public virtual pure; function owner() public virtual view returns(address); @@ -70,6 +72,7 @@ abstract contract Offline { } // from https://solidity-by-example.org/signature/ + // Published under MIT license function splitSignature(bytes memory sig) public pure returns (bytes32 r, bytes32 s, uint8 v) { require(sig.length == 65, "invalid signature length"); @@ -95,6 +98,7 @@ abstract contract Offline { } // https://ethereum.stackexchange.com/questions/10811/solidity-concatenate-uint-into-a-string + // Published under license CC BY-SA 3.0 function uintToString(uint v) public pure returns (string memory str) { uint maxlength = 100; bytes memory reversed = new bytes(maxlength);