eth-offline

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

commit 64fe7e25287bc3fcdbf4a575faf8c8faa83f42e0
parent 122da8e693ba5c660d070683689630e46ad01dd7
Author: lash <dev@holbrook.no>
Date:   Tue, 14 Mar 2023 08:34:20 +0000

Fix uint cast in uint to string contract method

Diffstat:
Mpython/eth_offline/data/Offline.bin | 4++--
Apython/eth_offline/data/Offline.json | 1+
Mpython/tests/test_basic.py | 111+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Asolidity/Makefile | 10++++++++++
Msolidity/OfflineBase.sol | 48++++++++++++++++++++++++++----------------------
5 files changed, 148 insertions(+), 26 deletions(-)

diff --git a/python/eth_offline/data/Offline.bin b/python/eth_offline/data/Offline.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550611628806100606000396000f3fe608060405234801561001057600080fd5b50600436106100a5576000357c010000000000000000000000000000000000000000000000000000000090048063a7bb580311610078578063a7bb580314610145578063aa1d23a014610177578063aeb02492146101a7578063e9395679146101d7576100a5565b8063557ba855146100aa578063772295f6146100c65780638da5cb5b146100f757806397aba7f914610115575b600080fd5b6100c460048036038101906100bf9190610d64565b610207565b005b6100e060048036038101906100db9190610d64565b61020a565b6040516100ee929190610e6d565b60405180910390f35b6100ff6104ba565b60405161010c9190610e9d565b60405180910390f35b61012f600480360381019061012a9190610eee565b6104e3565b60405161013c9190610e9d565b60405180910390f35b61015f600480360381019061015a9190610d64565b610552565b60405161016e93929190610f75565b60405180910390f35b610191600480360381019061018c9190610fac565b6105ba565b60405161019e9190610e9d565b60405180910390f35b6101c160048036038101906101bc9190610fac565b6109a2565b6040516101ce919061103f565b60405180910390f35b6101f160048036038101906101ec9190611090565b6109f0565b6040516101fe9190611112565b60405180910390f35b50565b600060608060606014855111610255576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161024c90611180565b60405180910390fd5b601467ffffffffffffffff8111156102705761026f610c39565b5b6040519080825280601f01601f1916602001820160405280156102a25781602001600182028036833780820191505090505b509150601485516102b391906111cf565b67ffffffffffffffff8111156102cc576102cb610c39565b5b6040519080825280601f01601f1916602001820160405280156102fe5781602001600182028036833780820191505090505b50905060005b82518110156103bf578581815181106103205761031f611203565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000283828151811061037d5761037c611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806103b790611232565b915050610304565b5060005b815181101561048a57856014826103da919061127a565b815181106103eb576103ea611203565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000282828151811061044857610447611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061048290611232565b9150506103c3565b5061049481610207565b8161049e9061130f565b6c01000000000000000000000000900481935093505050915091565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000806000806104f285610552565b9250925092506001868285856040516000815260200160405260405161051b9493929190611376565b6020604051602081039080840390855afa15801561053d573d6000803e3d6000fd5b50505060206040510351935050505092915050565b6000806000604184511461059b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161059290611407565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b600060606000806060600080600060148a516105d6919061127a565b94506105e1856109f0565b93508351925082601a866105f5919061127a565b6105ff919061127a565b67ffffffffffffffff81111561061857610617610c39565b5b6040519080825280601f01601f19166020018201604052801561064a5781602001600182028036833780820191505090505b50965060005b601a81101561070a57604051602001610668906114a4565b604051602081830303815290604052610680906114fa565b81601a811061069257610691611203565b5b1a7f0100000000000000000000000000000000000000000000000000000000000000028882815181106106c8576106c7611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061070290611232565b915050610650565b50601a82610718919061127a565b915060005b838110156107e25784818151811061073857610737611203565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000288848361078f919061127a565b815181106107a05761079f611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806107da90611232565b91505061071d565b5082826107ef919061127a565b9150306c0100000000000000000000000002905060005b60148110156108a55781816014811061082257610821611203565b5b1a7f010000000000000000000000000000000000000000000000000000000000000002888483610852919061127a565b8151811061086357610862611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061089d90611232565b915050610806565b506014826108b3919061127a565b915060005b8a5181101561097e578a81815181106108d4576108d3611203565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000288848361092b919061127a565b8151811061093c5761093b611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061097690611232565b9150506108b8565b5086805190602001209550610993868a6104e3565b97505050505050505092915050565b6000806109ad6104ba565b90506109b984846105ba565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161491505092915050565b606060006064905060008167ffffffffffffffff811115610a1457610a13610c39565b5b6040519080825280601f01601f191660200182016040528015610a465781602001600182028036833780820191505090505b50905060005b60008514610ad8576000600a86610a639190611590565b9050600a86610a7291906115c1565b9550806030610a81919061127a565b600102838380610a9090611232565b945081518110610aa357610aa2611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050610a4c565b60008167ffffffffffffffff811115610af457610af3610c39565b5b6040519080825280601f01601f191660200182016040528015610b265781602001600182028036833780820191505090505b50905060005b82811015610bfd578381600185610b4391906111cf565b610b4d91906111cf565b81518110610b5e57610b5d611203565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002828281518110610bbb57610bba611203565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610bf590611232565b915050610b2c565b5080945050505050919050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610c7182610c28565b810181811067ffffffffffffffff82111715610c9057610c8f610c39565b5b80604052505050565b6000610ca3610c0a565b9050610caf8282610c68565b919050565b600067ffffffffffffffff821115610ccf57610cce610c39565b5b610cd882610c28565b9050602081019050919050565b82818337600083830152505050565b6000610d07610d0284610cb4565b610c99565b905082815260208101848484011115610d2357610d22610c23565b5b610d2e848285610ce5565b509392505050565b600082601f830112610d4b57610d4a610c1e565b5b8135610d5b848260208601610cf4565b91505092915050565b600060208284031215610d7a57610d79610c14565b5b600082013567ffffffffffffffff811115610d9857610d97610c19565b5b610da484828501610d36565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610dd882610dad565b9050919050565b610de881610dcd565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610e28578082015181840152602081019050610e0d565b60008484015250505050565b6000610e3f82610dee565b610e498185610df9565b9350610e59818560208601610e0a565b610e6281610c28565b840191505092915050565b6000604082019050610e826000830185610ddf565b8181036020830152610e948184610e34565b90509392505050565b6000602082019050610eb26000830184610ddf565b92915050565b6000819050919050565b610ecb81610eb8565b8114610ed657600080fd5b50565b600081359050610ee881610ec2565b92915050565b60008060408385031215610f0557610f04610c14565b5b6000610f1385828601610ed9565b925050602083013567ffffffffffffffff811115610f3457610f33610c19565b5b610f4085828601610d36565b9150509250929050565b610f5381610eb8565b82525050565b600060ff82169050919050565b610f6f81610f59565b82525050565b6000606082019050610f8a6000830186610f4a565b610f976020830185610f4a565b610fa46040830184610f66565b949350505050565b60008060408385031215610fc357610fc2610c14565b5b600083013567ffffffffffffffff811115610fe157610fe0610c19565b5b610fed85828601610d36565b925050602083013567ffffffffffffffff81111561100e5761100d610c19565b5b61101a85828601610d36565b9150509250929050565b60008115159050919050565b61103981611024565b82525050565b60006020820190506110546000830184611030565b92915050565b6000819050919050565b61106d8161105a565b811461107857600080fd5b50565b60008135905061108a81611064565b92915050565b6000602082840312156110a6576110a5610c14565b5b60006110b48482850161107b565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60006110e4826110bd565b6110ee81856110c8565b93506110fe818560208601610e0a565b61110781610c28565b840191505092915050565b6000602082019050818103600083015261112c81846110d9565b905092915050565b7f4552525f434f4e54454e54530000000000000000000000000000000000000000600082015250565b600061116a600c836110c8565b915061117582611134565b602082019050919050565b600060208201905081810360008301526111998161115d565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006111da8261105a565b91506111e58361105a565b92508282039050818111156111fd576111fc6111a0565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600061123d8261105a565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361126f5761126e6111a0565b5b600182019050919050565b60006112858261105a565b91506112908361105a565b92508282019050808211156112a8576112a76111a0565b5b92915050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b60006112f682516112be565b80915050919050565b60008160020a8302905092915050565b600061131a82610dee565b82611324846112ae565b905061132f816112ea565b9250601482101561136f5761136a7fffffffffffffffffffffffffffffffffffffffff000000000000000000000000836014036008026112ff565b831692505b5050919050565b600060808201905061138b6000830187610f4a565b6113986020830186610f66565b6113a56040830185610f4a565b6113b26060830184610f4a565b95945050505050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b60006113f16018836110c8565b91506113fc826113bb565b602082019050919050565b60006020820190508181036000830152611420816113e4565b9050919050565b600081905092915050565b7f307831393435373436383635373236353735366432303533363936373665363560008201527f3634323034643635373337333631363736353361306100000000000000000000602082015250565b600061148e603683611427565b915061149982611432565b603682019050919050565b60006114af82611481565b9150819050919050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000082169050919050565b60006114f182516114b9565b80915050919050565b600061150582610dee565b8261150f846112ae565b905061151a816114e5565b9250601a82101561155a576115557fffffffffffffffffffffffffffffffffffffffffffffffffffff00000000000083601a036008026112ff565b831692505b5050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061159b8261105a565b91506115a68361105a565b9250826115b6576115b5611561565b5b828206905092915050565b60006115cc8261105a565b91506115d78361105a565b9250826115e7576115e6611561565b5b82820490509291505056fea2646970667358221220b100f5ede2d5731f6ea861c88ad1802aac0d821239fbef797283fdd94cbdfbab64736f6c63430008120033 -\ No newline at end of file +608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061157e806100606000396000f3fe608060405234801561001057600080fd5b50600436106100b0576000357c010000000000000000000000000000000000000000000000000000000090048063a7bb580311610083578063a7bb580314610150578063aa1d23a014610182578063aeb02492146101b2578063ca9bc523146101e2578063e939567914610212576100b0565b8063557ba855146100b5578063772295f6146100d15780638da5cb5b1461010257806397aba7f914610120575b600080fd5b6100cf60048036038101906100ca9190610dd2565b610242565b005b6100eb60048036038101906100e69190610dd2565b610245565b6040516100f9929190610edb565b60405180910390f35b61010a6104f5565b6040516101179190610f0b565b60405180910390f35b61013a60048036038101906101359190610f5c565b61051e565b6040516101479190610f0b565b60405180910390f35b61016a60048036038101906101659190610dd2565b61058d565b60405161017993929190610fe3565b60405180910390f35b61019c6004803603810190610197919061101a565b6105f5565b6040516101a99190610f0b565b60405180910390f35b6101cc60048036038101906101c7919061101a565b610623565b6040516101d991906110ad565b60405180910390f35b6101fc60048036038101906101f79190610dd2565b610671565b60405161020991906110c8565b60405180910390f35b61022c60048036038101906102279190611120565b610a3f565b60405161023991906111a2565b60405180910390f35b50565b600060608060606014855111610290576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161028790611210565b60405180910390fd5b601467ffffffffffffffff8111156102ab576102aa610ca7565b5b6040519080825280601f01601f1916602001820160405280156102dd5781602001600182028036833780820191505090505b509150601485516102ee919061125f565b67ffffffffffffffff81111561030757610306610ca7565b5b6040519080825280601f01601f1916602001820160405280156103395781602001600182028036833780820191505090505b50905060005b82518110156103fa5785818151811061035b5761035a611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028382815181106103b8576103b7611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806103f2906112c2565b91505061033f565b5060005b81518110156104c55785601482610415919061130a565b8151811061042657610425611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f01000000000000000000000000000000000000000000000000000000000000000282828151811061048357610482611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806104bd906112c2565b9150506103fe565b506104cf81610242565b816104d99061139f565b6c01000000000000000000000000900481935093505050915091565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b60008060008061052d8561058d565b925092509250600186828585604051600081526020016040526040516105569493929190611406565b6020604051602081039080840390855afa158015610578573d6000803e3d6000fd5b50505060206040510351935050505092915050565b600080600060418451146105d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105cd90611497565b60405180910390fd5b6020840151925060408401519150606084015160001a90509193909250565b600080606061060385610671565b905080805190602001209150610619828561051e565b9250505092915050565b60008061062e6104f5565b905061063a84846105f5565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff161491505092915050565b6060806000606060008060006014885161068b919061130a565b945061069685610a3f565b9350835192508483601a6106aa919061130a565b6106b4919061130a565b67ffffffffffffffff8111156106cd576106cc610ca7565b5b6040519080825280601f01601f1916602001820160405280156106ff5781602001600182028036833780820191505090505b50955060005b601a8110156107bc577919457468657265756d205369676e6564204d6573736167653a0a66010000000000000281601a811061074457610743611293565b5b1a7f01000000000000000000000000000000000000000000000000000000000000000287828151811061077a57610779611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806107b4906112c2565b915050610705565b50601a826107ca919061130a565b915060005b83811015610894578481815181106107ea576107e9611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002878483610841919061130a565b8151811061085257610851611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061088c906112c2565b9150506107cf565b5082826108a1919061130a565b9150306c0100000000000000000000000002905060005b6014811015610957578181601481106108d4576108d3611293565b5b1a7f010000000000000000000000000000000000000000000000000000000000000002878483610904919061130a565b8151811061091557610914611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350808061094f906112c2565b9150506108b8565b50601482610965919061130a565b915060005b8851811015610a305788818151811061098657610985611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f0100000000000000000000000000000000000000000000000000000000000000028784836109dd919061130a565b815181106109ee576109ed611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610a28906112c2565b91505061096a565b50859650505050505050919050565b606060006064905060008167ffffffffffffffff811115610a6357610a62610ca7565b5b6040519080825280601f01601f191660200182016040528015610a955781602001600182028036833780820191505090505b50905060005b60008514610b46576000600a86610ab291906114e6565b9050600a86610ac19190611517565b9550806030610ad0919061130a565b7f010000000000000000000000000000000000000000000000000000000000000002838380610afe906112c2565b945081518110610b1157610b10611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050610a9b565b60008167ffffffffffffffff811115610b6257610b61610ca7565b5b6040519080825280601f01601f191660200182016040528015610b945781602001600182028036833780820191505090505b50905060005b82811015610c6b578381600185610bb1919061125f565b610bbb919061125f565b81518110610bcc57610bcb611293565b5b60200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002828281518110610c2957610c28611293565b5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508080610c63906112c2565b915050610b9a565b5080945050505050919050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610cdf82610c96565b810181811067ffffffffffffffff82111715610cfe57610cfd610ca7565b5b80604052505050565b6000610d11610c78565b9050610d1d8282610cd6565b919050565b600067ffffffffffffffff821115610d3d57610d3c610ca7565b5b610d4682610c96565b9050602081019050919050565b82818337600083830152505050565b6000610d75610d7084610d22565b610d07565b905082815260208101848484011115610d9157610d90610c91565b5b610d9c848285610d53565b509392505050565b600082601f830112610db957610db8610c8c565b5b8135610dc9848260208601610d62565b91505092915050565b600060208284031215610de857610de7610c82565b5b600082013567ffffffffffffffff811115610e0657610e05610c87565b5b610e1284828501610da4565b91505092915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610e4682610e1b565b9050919050565b610e5681610e3b565b82525050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610e96578082015181840152602081019050610e7b565b60008484015250505050565b6000610ead82610e5c565b610eb78185610e67565b9350610ec7818560208601610e78565b610ed081610c96565b840191505092915050565b6000604082019050610ef06000830185610e4d565b8181036020830152610f028184610ea2565b90509392505050565b6000602082019050610f206000830184610e4d565b92915050565b6000819050919050565b610f3981610f26565b8114610f4457600080fd5b50565b600081359050610f5681610f30565b92915050565b60008060408385031215610f7357610f72610c82565b5b6000610f8185828601610f47565b925050602083013567ffffffffffffffff811115610fa257610fa1610c87565b5b610fae85828601610da4565b9150509250929050565b610fc181610f26565b82525050565b600060ff82169050919050565b610fdd81610fc7565b82525050565b6000606082019050610ff86000830186610fb8565b6110056020830185610fb8565b6110126040830184610fd4565b949350505050565b6000806040838503121561103157611030610c82565b5b600083013567ffffffffffffffff81111561104f5761104e610c87565b5b61105b85828601610da4565b925050602083013567ffffffffffffffff81111561107c5761107b610c87565b5b61108885828601610da4565b9150509250929050565b60008115159050919050565b6110a781611092565b82525050565b60006020820190506110c2600083018461109e565b92915050565b600060208201905081810360008301526110e28184610ea2565b905092915050565b6000819050919050565b6110fd816110ea565b811461110857600080fd5b50565b60008135905061111a816110f4565b92915050565b60006020828403121561113657611135610c82565b5b60006111448482850161110b565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60006111748261114d565b61117e8185611158565b935061118e818560208601610e78565b61119781610c96565b840191505092915050565b600060208201905081810360008301526111bc8184611169565b905092915050565b7f4552525f434f4e54454e54530000000000000000000000000000000000000000600082015250565b60006111fa600c83611158565b9150611205826111c4565b602082019050919050565b60006020820190508181036000830152611229816111ed565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061126a826110ea565b9150611275836110ea565b925082820390508181111561128d5761128c611230565b5b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006112cd826110ea565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036112ff576112fe611230565b5b600182019050919050565b6000611315826110ea565b9150611320836110ea565b925082820190508082111561133857611337611230565b5b92915050565b6000819050602082019050919050565b60007fffffffffffffffffffffffffffffffffffffffff00000000000000000000000082169050919050565b6000611386825161134e565b80915050919050565b60008160020a8302905092915050565b60006113aa82610e5c565b826113b48461133e565b90506113bf8161137a565b925060148210156113ff576113fa7fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008360140360080261138f565b831692505b5050919050565b600060808201905061141b6000830187610fb8565b6114286020830186610fd4565b6114356040830185610fb8565b6114426060830184610fb8565b95945050505050565b7f696e76616c6964207369676e6174757265206c656e6774680000000000000000600082015250565b6000611481601883611158565b915061148c8261144b565b602082019050919050565b600060208201905081810360008301526114b081611474565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006114f1826110ea565b91506114fc836110ea565b92508261150c5761150b6114b7565b5b828206905092915050565b6000611522826110ea565b915061152d836110ea565b92508261153d5761153c6114b7565b5b82820490509291505056fea2646970667358221220188593ee01bbc2e2f184913703fe5e7a903129044a2017658dfaef16b2f12a7864736f6c63430008120033 +\ No newline at end of file diff --git a/python/eth_offline/data/Offline.json b/python/eth_offline/data/Offline.json @@ -0,0 +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"}] diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py @@ -109,7 +109,7 @@ class TestOfflineEth(EthTesterCase): self.assertTrue(same_hex(r[24:64], self.accounts[1])) - def test_verify(self): + def test_message(self): contract_bin = bytes.fromhex(strip_0x(self.address)) beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) msg_bin = b'bar' @@ -118,7 +118,43 @@ class TestOfflineEth(EthTesterCase): sig = self.signer.sign_ethereum_message(self.accounts[1], msg_tosign) sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big') - logg.debug('message is signed by {}'.format(self.accounts[1])) + logg.debug('message is account {} {} signed by {}'.format(self.accounts[2], msg_data.hex(), self.accounts[1])) + + c = TxFactory(self.chain_spec) + j = JSONRPCRequest() + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('toRequest') + enc.typ(ABIContractType.BYTES) + enc.bytes(msg_data.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) + rb = r[-192:] + rb = rb[56:] + + self.assertTrue(same_hex(rb[:40], self.address)) + self.assertTrue(same_hex(rb[40:80], self.accounts[2])) + self.assertTrue(same_hex(rb[80:86], b'bar'.hex())) + + + def test_magic_request(self): + contract_bin = bytes.fromhex(strip_0x(self.address)) + beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) + msg_bin = b'bar' + msg_data = beneficiary_bin + msg_bin + msg_tosign = contract_bin + msg_data + + sig = self.signer.sign_ethereum_message(self.accounts[1], msg_tosign) + sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big') + logg.debug('message is {} signed by {}'.format(msg_data.hex(), self.accounts[1])) c = TxFactory(self.chain_spec) j = JSONRPCRequest() @@ -140,6 +176,77 @@ class TestOfflineEth(EthTesterCase): r = self.rpc.do(o) r = strip_0x(r) + self.assertTrue(same_hex(r[24:64], self.accounts[1])) + + + def test_verify(self): + contract_bin = bytes.fromhex(strip_0x(self.address)) + beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) + msg_bin = b'bar' + msg_data = beneficiary_bin + msg_bin + msg_tosign = contract_bin + msg_data + + sig = self.signer.sign_ethereum_message(self.accounts[0], msg_tosign) + sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big') + logg.debug('message is {} signed by {}'.format(msg_data.hex(), self.accounts[0])) + + c = TxFactory(self.chain_spec) + j = JSONRPCRequest() + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('verifyRequest') + enc.typ(ABIContractType.BYTES) + enc.typ(ABIContractType.BYTES) + enc.bytes(msg_data.hex()) + enc.bytes(sig.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) + + + + def test_verify_fail_owner(self): + contract_bin = bytes.fromhex(strip_0x(self.address)) + beneficiary_bin = bytes.fromhex(strip_0x(self.accounts[2])) + msg_bin = b'bar' + msg_data = beneficiary_bin + msg_bin + msg_tosign = contract_bin + msg_data + + sig = self.signer.sign_ethereum_message(self.accounts[1], msg_tosign) + sig = sig[:64] + (sig[64] + 27).to_bytes(1, byteorder='big') + logg.debug('message is {} signed by {}'.format(msg_data.hex(), self.accounts[1])) + + c = TxFactory(self.chain_spec) + j = JSONRPCRequest() + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('verifyRequest') + enc.typ(ABIContractType.BYTES) + enc.typ(ABIContractType.BYTES) + enc.bytes(msg_data.hex()) + enc.bytes(sig.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) + if __name__ == '__main__': unittest.main() diff --git a/solidity/Makefile b/solidity/Makefile @@ -0,0 +1,10 @@ +SOLC = /usr/bin/solc + +all: + $(SOLC) --bin Offline.sol --evm-version byzantium | awk 'NR==4' > Offline.bin + truncate -s -1 Offline.bin + $(SOLC) --abi Offline.sol --evm-version byzantium | awk 'NR==4' > Offline.json + +install: all + cp -v Offline.bin ../python/eth_offline/data/ + cp -v Offline.json ../python/eth_offline/data/ diff --git a/solidity/OfflineBase.sol b/solidity/OfflineBase.sol @@ -4,55 +4,59 @@ pragma solidity ^0.8.0; abstract contract Offline { - bytes26 constant prefix = bytes26(abi.encodePacked("0x19457468657265756d205369676e6564204d6573736167653a0a")); + bytes26 constant prefix = bytes26(0x19457468657265756d205369676e6564204d6573736167653a0a); function fromRequest(bytes memory _data, bytes memory _signature) public view returns(address) { - //address beneficiary; - //bytes memory extra; - bytes memory message; bytes32 messageDigest; + bytes memory message; + + message = toRequest(_data); + + messageDigest = keccak256(message); + + return recoverSigner(messageDigest, _signature); + } + + function verifyRequest(bytes memory _data, bytes memory _signature) public view returns(bool) { + address _owner = owner(); + + return _owner == fromRequest(_data, _signature); + } + + function toRequest(bytes memory _data) public view returns(bytes memory) { + bytes memory message; uint256 messageLength; bytes memory messageLengthStr; uint256 messageLengthLength; uint256 c; bytes20 contractBytes; - - //(beneficiary, extra) = splitData(_data); + messageLength = _data.length + 20; messageLengthStr = bytes(uintToString(uint(messageLength))); messageLengthLength = bytes(messageLengthStr).length; - message = new bytes(messageLength + 26 + messageLengthLength); + message = new bytes(26 + messageLengthLength + messageLength); - for (uint256 i; i < 26; i++) { + for (uint256 i = 0; i < 26; i++) { message[i] = prefix[i]; } c += 26; - for (uint256 i; i < messageLengthLength; i++) { + for (uint256 i = 0; i < messageLengthLength; i++) { message[i+c] = messageLengthStr[i]; } c += messageLengthLength; contractBytes = bytes20(address(this)); - for (uint256 i; i < 20; i++) { + for (uint256 i = 0; i < 20; i++) { message[i+c] = contractBytes[i]; } c += 20; - for (uint256 i; i < _data.length; i++) { + for (uint256 i = 0; i < _data.length; i++) { message[i+c] = _data[i]; } - - messageDigest = keccak256(message); - - return recoverSigner(messageDigest, _signature); - } - - function verifyRequest(bytes memory _data, bytes memory _signature) public view returns(bool) { - address _owner = owner(); - - return _owner == fromRequest(_data, _signature); + return message; } function verifyExtraData(bytes memory _data) public virtual pure; @@ -98,7 +102,7 @@ abstract contract Offline { while (v != 0) { uint remainder = v % 10; v = v / 10; - reversed[i++] = bytes1(bytes32(48 + remainder)); + reversed[i++] = bytes1(uint8(48 + remainder)); } bytes memory s = new bytes(i); for (uint j = 0; j < i; j++) {