-
-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce OrderedMap into CBOR and use it in Cardano #1672
Conversation
|
please squash&rebase. as an aside, if you could check that new behavior in pagination (each paging event sends a ButtonRequest) works fine with Cardano wallets, that would be nice |
Items of an OrderedMap are included in CBOR as they come without sorting them in any way.
a68ee6a
to
cc14ffb
Compare
Squashed and rebased. I tried generating the test fixtures twice - with an emulator running without animations and without any emulator running - however it changed all of the fixtures both times. Is this currently expected or should I play around with it? I tried signing a transaction and deriving an address through Adalite and it worked fine with the physical device, but it was failing on the emulator - as soon as I swiped, the action failed. I used https://github.com/trezor/trezord-go and |
something must be going wrong, because without emulator you can't generate the UI fixtures. (the images aren't exported from hardware) |
fixture added in 2491f87 |
Can't reproduce the problem, so I'm going to assume that this is some sort of glitch. If you managed to isolate it, that would be great though. |
CI green, merging. |
When I said "without any emulator running", I meant that I had no emulator started up when calling I'll give it another try tomorrow. I'm recently switched from Linux to a M1 macbook with nix-shell so that might be a part of the problem. Thanks for adding the fixture and for merging 👍 |
Exactly. I'm actually not sure what happens if there is an emulator running; I'd expect some sort of conflict and weird state. Also to save time you can run only the tests that you need via For example this is what I do: |
Hi @matejcik, sorry for getting back to you a bit late. Thanks for the filtering tip, I'm not sure why I haven't used it with the UI tests. I tried generating the fixtures again on the mac a couple of times, but all the fixtures always changed. I tried running with nix-shell and without it (although emulator was still built through nix-shell). It works fine on the Linux machine also with nix-shell. I haven't looked deeper into it as I don't understand enough details of what's going on. I'll play around with it again the next time I'll be generating the fixtures. |
Ordering output multi asset policies and the tokens in them causes interoperability problems with cardano-cli because cardano-cli adds policies and tokens into the transaction as they come. Trezor sorts the dicts going into CBOR by default, which is in line with Canonical CBOR definition from the CBOR RFC. We're working on a CIP which would define canonical CBOR spec for Cardano which would be in line with what cardano-cli does and would standardise transaction serialisation format. Until this CIP is accepted, we should be including the assets in the order in which they came. That's what this PR does.
As Python's
dict
s don't preserve the order of items andOrderedDict
fromcollections
orucollections
is not available, we needed to introduce a new container,OrderedMap
, which is a simple implementation of a KVP list which preserves the order of its items while being serialised into CBOR as a Map. TheOrderedMap
implements only the necessary functionality - it's in no way a complete container, but IMHO that is OK for our purposes. We weren't able to makeOrderedMap
correctly type annotated and generic i.e.class OrderedMap(Generic[K, V])
. We tried doing something similar as is done inmathcheck.py
but it didn't work sinceGeneric[K, V]
is not valid Python syntax.OrderedMap
is now used in Cardano transaction signing for serialising policies, assets and also withdrawals, since these items might previously get reordered when being serialised. Since we don't want duplicate withdrawals to be included in CBOR we also validate that there are no duplicate paths for withdrawals - previously they were simply overwritten in the dict and it seems the validation should have been there also then.It would be awesome if we could get this into the July release 🙏