Comments (34)
Great!
The whole area of code needs to be rewritten. I only wrote it in one weekend. It can also be performance optimized. It was a literal translation from Java and I took shortcuts because I didn't understand Java too well. When I have time, I will clean this up and make it more readable.
from trezor.net.
All ok on my side, see also the final tests for Message Signing, Ether Transaction and Token Transaction. I need to do further checks on 155 signatures and big data elements. But I don't think it will be an issue. Next step to integrate in Nethereum like ledger :) :)
from trezor.net.
@juanfranblanco @ThatSlyGuy incidentally, transaction signing now works on KeepKey (KeepKey.Net). It's basically all the same code.
from trezor.net.
@ThatSlyGuy @MelbourneDeveloper
Hi I have not managed to sign a transaction successfully yet, banging my head on combinations. Well I do sign stuff, but it is incorrect the response in comparison with Nethereum, so some of the parameters are not passed correctly.
Signing messages work, not transactions :) I moved to messages to have a simple test case to start with.
This is message signing using Nethereum
var message = new EthereumSignMessage
{
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
Message = Encoding.UTF8.GetBytes("Hello").ToHex().ToHexBytes()
};
var messageSignature = await trezorManager.SendMessageAsync<EthereumMessageSignature, EthereumSignMessage>(message);
//Same as first address
Console.WriteLine(ToHex(messageSignature.Address));
var signer = new Nethereum.Signer.EthereumMessageSigner();
var messageSignature2 = signer.EncodeUTF8AndSign("Hello", new EthECKey(
"0x2e14c29aaecd1b7c681154d41f50c4bb8b6e4299a431960ed9e860e39cae6d29"));
And this is where I am with transaction signing, GasLimit is recognised and address correctly, from the response, but it does not recognise the value.
var txMessage = new EthereumSignTx
{
Nonce = 10.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
GasPrice = 10.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
GasLimit = 21000.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
To = "689c56aef474df92d44a1b70850f808488f9769c".ToHexBytes(),
Value = BigInteger.Parse("10000000000000000000").ToBytesForRLPEncoding().ToHex().ToHexBytes(),
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
//ChainId = 1
};
var transaction = await trezorManager.SendMessageAsync<EthereumTxRequest, EthereumSignTx>(txMessage);
from trezor.net.
@MelbourneDeveloper This is great! The changes you made in the issue10 branch seemed to have completely fixed everything, thanks a lot! Everything seems to be correctly and consistently displayed to the Trezor.
@juanfranblanco The UNKN thing is just a result of not including the ChainId in the EthereumSignTx
initialization. If the ChainId is set to 1, then the Trezor displays ETH as the currency. If the ChainId is set to 4 (rinkeby), then the Trezor displays tETH. When no ChainId is included, it is not serialized, which results in the currency type appearing as UNKN.
[TestMethod]
public async Task SignEthereumTransaction2()
{
await GetAndInitialize();
var txMessage = new EthereumSignTx
{
Nonce = 10.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
GasPrice = 1000000000.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
GasLimit = 21000.ToBytesForRLPEncoding().ToHex().ToHexBytes(),
To = "689c56aef474df92d44a1b70850f808488f9769c".ToHexBytes(),
Value = BigInteger.Parse("10000000000000000000").ToBytesForRLPEncoding().ToHex().ToHexBytes(),
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
ChainId = 1
};
var transaction = await TrezorManager.SendMessageAsync<EthereumTxRequest, EthereumSignTx>(txMessage);
Assert.AreEqual(transaction.SignatureR.Length, 32);
Assert.AreEqual(transaction.SignatureS.Length, 32);
}
from trezor.net.
Cool the ChainId makes different types of Ether.
On a similar fashion there is a registry of token addresses, if the address match the amount of tokens will be transferred.
from trezor.net.
@ThatSlyGuy have you looked at #9 ?
I believe that 9# has been fixed.
from trezor.net.
This stuff does seem strange. It seems to be doing the same thing with the latest code. It is is sending the EthereumSignTx message which is 58:
from trezor.net.
It's possible that there are still bugs in the reading/writing to the device.
from trezor.net.
@juanfranblanco have you debugged the helper methods for ToHex and ToHexBytes etc? I'm not 100% sure that they're correct. If so...
Are you up for doing a test with the Trezor python library ? That would determine if the problem is in the library or in the parameters being passed. If the input is the same and the output is different, it probably means there is a bug in my library and I can take it from there.
from trezor.net.
@MelbourneDeveloper yes that was the next step.. the ToHex() is Nethereum the ToHexBytes() is yours but only for strings, on a documentation I read the need to remove the 0x and use hex strings.. hence GasLimit is recognised. I have to stop this for a while as it was lots of trying and error. But yeah ToHexBytes for a string seem to work correctly, based on the message, GasLimit and the Address.
from trezor.net.
Although it might be something with the Transaction Type, that was my other thought.
from trezor.net.
@juanfranblanco @ThatSlyGuy the problem is pretty clear. On a basic level, the To address is completely wrong. I'm getting the same result with KeepKey. It could be that the address is being sent to the device incorrectly, or it could be that the code is reading it incorrectly from the device.
There's enough information here for me to investigate. I'll update you when I can confirm whether or not there is an obvious bug.
from trezor.net.
I don't have a problem with the To address (check my code) but it appears as "send message", so it might the transaction type. If you try really hard you will see the address here "689c56aef474df92d44a1b70850f808488f9769c"
from trezor.net.
Here is the full program, it is using the "old" TrezorManager https://github.com/juanfranblanco/Trezor.Net/blob/master/src/Trezor.Net.Sample/Program.cs
from trezor.net.
Ok further analysis https://github.com/trezor/trezor-mcu/blob/master/firmware/ethereum.c#L267-L268 the Value is send as 0 hence we have "message". The txn type is for WanChain so ignore that.
from trezor.net.
@juanfranblanco thanks! Actually, I might have found the problem. I will get back to you soon.
from trezor.net.
Cool :)
from trezor.net.
@juanfranblanco
Can you try a pull from branch Issue10? I believe this has fixed @ThatSlyGuy 's problem. It may fix yours.
from trezor.net.
Sure
from trezor.net.
@juanfranblanco I have added the unit test SignEthereumTransaction2 to master/Issues10 which is from your sample app. You can get it by doing a pull. Am I right in understanding that the problem is the Gas limit is coming up as 210000, and the currency is saying UNK?
from trezor.net.
What do you expect this test to display on the Trezor?
from trezor.net.
Correct that is where we are now, although your fix has allowed to see the Value
from trezor.net.
It should be 21000 and 10 Ether, let me recreate in MEW and post some shots.
from trezor.net.
Unfortunately, I have to call it a night. But, I can see that there is an issue. I think I have some ideas about what is happening. The Issue10 branch is one step closer. I think I'll be able to fix it tomorrow.
from trezor.net.
@ThatSlyGuy can you see if your issues are any closer with the Issue10 branch?
from trezor.net.
Have a great sleep, yes that branch fixed reading the Value so that is a great start, I don't get the extra zero of the GasLimit.
from trezor.net.
Ok re-reading the description it is the total Wei Price to it is 21k * 10 hence the 210000, so that is correct. I have checked the signatures and everything is fine.
Also the simplified test case is here, just use Nethereum extensions for this.
var txMessage = new EthereumSignTx
{
Nonce = 10.ToBytesForRLPEncoding(),
GasPrice = 10.ToBytesForRLPEncoding(),
GasLimit = 21000.ToBytesForRLPEncoding(),
To = "689c56aef474df92d44a1b70850f808488f9769c".HexToByteArray(),
Value = BigInteger.Parse("10000000000000000000").ToBytesForRLPEncoding(),
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
};
var trezorTransactionSignature = await trezorManager.SendMessageAsync<EthereumTxRequest, EthereumSignTx>(txMessage);
var transactionSigner = new TransactionSigner();
var nethereumSignature = transactionSigner.SignTransaction("0x2e14c29aaecd1b7c681154d41f50c4bb8b6e4299a431960ed9e860e39cae6d29",
"0x689c56aef474df92d44a1b70850f808488f9769c", BigInteger.Parse("10000000000000000000"), 10, 10, 21000);
var transactionRecovered = new Transaction(nethereumSignature.HexToByteArray());
Console.WriteLine("Trezor R: " + trezorTransactionSignature.SignatureR.ToHex());
Console.WriteLine("Nethereum R: " + transactionRecovered.Signature.R.ToHex());
Console.WriteLine("Trezor S:" + trezorTransactionSignature.SignatureS.ToHex());
Console.WriteLine("Nethereum S: " + transactionRecovered.Signature.S.ToHex());
Console.WriteLine("Trezor V:" + trezorTransactionSignature.SignatureV);
Console.WriteLine("Nethereum V: " + new BigInteger(transactionRecovered.Signature.V));
from trezor.net.
@MelbourneDeveloper So the only issue is the currency UNK, the rest is correct and signing correctly. Next thing is signing token transactions or big data transactions.
from trezor.net.
More tidying on the message signing side:
var message = new EthereumSignMessage
{
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
Message = Encoding.UTF8.GetBytes("Hello")
};
Ill do some pull requests later
from trezor.net.
@MelbourneDeveloper here is a test for Token signing transfer:
var transfer = new TransferFunction();
transfer.To = "0x12890d2cce102216644c59daE5baed380d848301";
transfer.Value = 100000000000000000;
var data = transfer.GetCallData();
var txMessage2 = new EthereumSignTx
{
Nonce = 10.ToBytesForRLPEncoding(),
GasPrice = 10.ToBytesForRLPEncoding(),
GasLimit = 21000.ToBytesForRLPEncoding(),
To = "6810e776880c02933d47db1b9fc05908e5386b96".HexToByteArray(),
DataInitialChunk = data,
DataLength = (uint)data.Length,
AddressNs = KeyPath.Parse("m/44'/60'/0'/0/0").Indexes,
};
var trezorTransactionContractSignature = await trezorManager.SendMessageAsync<EthereumTxRequest, EthereumSignTx>(txMessage2);
var account = new Account("0x2e14c29aaecd1b7c681154d41f50c4bb8b6e4299a431960ed9e860e39cae6d29");
var rpcClient = new RpcClient(new Uri("http://localhost:8545"));
transfer.Nonce = 10;
transfer.GasPrice = 10;
transfer.FromAddress = account.Address;
transfer.Gas = 21000;
var transactionInput = transfer.CreateTransactionInput("0x6810e776880c02933d47db1b9fc05908e5386b96");
account.TransactionManager.Client = rpcClient;
var nettherumTransactionContractSignature = await account.TransactionManager.SignTransactionAsync(transactionInput);
var transactionContractRecovered = new Transaction(nettherumTransactionContractSignature.HexToByteArray());
Console.WriteLine("Trezor R: " + trezorTransactionContractSignature.SignatureR.ToHex());
Console.WriteLine("Nethereum R: " + transactionContractRecovered.Signature.R.ToHex());
Console.WriteLine("Trezor S:" + trezorTransactionContractSignature.SignatureS.ToHex());
Console.WriteLine("Nethereum S: " + transactionContractRecovered.Signature.S.ToHex());
Console.WriteLine("Trezor V:" + trezorTransactionContractSignature.SignatureV);
Console.WriteLine("Nethereum V: " + new BigInteger(transactionContractRecovered.Signature.V));
from trezor.net.
Hopefully there are no more Java arrays ;)
from trezor.net.
I have merged the fix in to master and will do a NuGet release.
@ThatSlyGuy ,The test SignEthereumTransaction still gives me crazy outputs on the display. Can you submit a pull request to fix the values on that test?
@juanfranblanco so transactions are all good now? I can close these issues?
from trezor.net.
@MelbourneDeveloper I'll work on that pull request next!
I'm going to close this issue now that everything seems good. I'll reopen it or create a new one if any other problems arise.
from trezor.net.
Related Issues (20)
- FxCop Code Rules
- Firmware 1.8.x Protobuffer Upgrade
- Remove ByteBuffer
- Unit Tests For All Contracts
- Passphrases are Not Handled HOT 1
- Get Address Backward Compatibility
- Get Address for all Coins
- Caradano Address
- Message Type Number Inccorect - Breaks Messages 303+
- Get Stellar Address
- Get NEM Address
- Get Tezos Address
- Issue with Trezor Model T Passphrase
- Incompatibility with Device.Net 3.x.x
- 'Method not found: 'System.Threading.Tasks.Task`1<Byte[]> Device.Net.IDevice.ReadAsync()'.' HOT 1
- After latest Trezor firmware update, not possible to sign TX. HOT 9
- Trezor.Sample stuck at Device.ReadAsync in TrezorManagerBase.cs HOT 9
- Ethereum Transactions that use 1559 require an update of the protobufs and message types
- Trezor.Net.Sample produces DLL (library) not EXE (console application) HOT 1
- Trezor.Net with LibUsb getting an error while reading response from a device
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from trezor.net.