-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/mintlayer pk #1
base: main
Are you sure you want to change the base?
Conversation
bddbd25
to
967640b
Compare
5abd648
to
798be63
Compare
I wouldn't merge this to master but rather created a separate branch like One thing to consider is that CI might not work for "our" master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I can see, there are still many FIXMEs and commented lines, so it seems like this is still work-in-progress.
core/embed/extmod/modtrezormintlayer/modtrezormintlayer-utils.h
Outdated
Show resolved
Hide resolved
core/src/trezor/crypto/bech32.py
Outdated
def reverse_convertbits( | ||
data: Sequence[int], frombits: int, tobits: int | ||
) -> list[int]: | ||
acc = 0 | ||
bits = 0 | ||
ret = [] | ||
maxv = (1 << frombits) - 1 | ||
for value in data: | ||
if value < 0 or (value >> tobits): | ||
raise ValueError # input value does not match `tobits` size | ||
acc = ((acc << tobits) | value) & ((1 << (frombits + tobits)) - 1) | ||
bits += tobits | ||
while bits >= frombits: | ||
bits -= frombits | ||
ret.append((acc >> bits) & maxv) | ||
return ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? As I can see, the existing convertbits
can convert in both directions, i.e. 8 to 5 and 5 to 8. Am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not working correctly in the other way.
a7ca54f
to
941d641
Compare
941d641
to
dd3f1e8
Compare
2d02cde
to
86275f8
Compare
86275f8
to
2a0e5ec
Compare
79e901f
to
180e245
Compare
180e245
to
0bf0d4a
Compare
3529ba2
to
a3bda3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This review is also quite superficial, because I still don't fully understand what calls what.
P.S. are there any tests for the new code?
* @embed | ||
*/ | ||
message MintlayerTransferTxOutput { | ||
required string address = 1; // destination address in Base58 encoding; script_type must be PAYTOADDRESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and in other places - there is no "script_type", so "script_type must be PAYTOADDRESS" makes no sense
* @embed | ||
*/ | ||
message MintlayerLockThenTransferTxOutput { | ||
optional string address = 1; // destination address in Base58 encoding; script_type must be PAYTOADDRESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this optional?
* @embed | ||
*/ | ||
message MintlayerDelegateStakingTxOutput { | ||
required bytes amount = 1; // the amount to stake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the amount to stake delegate
required MintlayerTokenTotalSupplyType type = 1; // the amount to stake | ||
optional bytes fixed_amount = 2; // the amount to stake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong comments
required bytes pool_id = 1; // the pool id | ||
required bytes pledge = 2; // the pledge amount | ||
required string staker = 3; // the staker destination address | ||
required string vrf_public_key = 4; // the VRF public key address | ||
required string decommission_key = 5; // the decommission key | ||
required uint32 margin_ratio_per_thousand = 6;// the margin ratio per thousand | ||
required bytes cost_per_block = 7; // the cost per block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plz align the comments like they do it in their original files. Same in other places.
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | ||
struct StakePoolData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder whether we should consider factoring out basic types like these from the main repo into a smaller subrepo to be able to re-use them in situations like this.
vstr_t pkh = {0}; | ||
vstr_init_len(&pkh, arr.len_or_err.len); | ||
int i = 0; | ||
for (; i < arr.len_or_err.len; i++) { | ||
((uint8_t *)pkh.buf)[i] = (uint8_t)arr.data[i]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Plz use a miningful name instead of "pkh" (it's not a public key hash here).
- Use
memcpy
instead of looping.
Same in other places.
mp_get_buffer_raise(delegation_id, &hash, MP_BUFFER_READ); | ||
if (hash.len != 32) { | ||
printf("invalid hash len: %ld", (long int)hash.len); | ||
mp_raise_ValueError("Invalid hash"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not repeat boilerplate over and over. E.g. this can be moved into a function mp_get_hash_raise
, which would call mp_get_buffer_raise
and then check the length.
handle_err(&arr); | ||
|
||
vstr_t pkh = {0}; | ||
vstr_init_len(&pkh, arr.len_or_err.len); | ||
int i = 0; | ||
for (; i < arr.len_or_err.len; i++) { | ||
((uint8_t *)pkh.buf)[i] = (uint8_t)arr.data[i]; | ||
} | ||
|
||
return mp_obj_new_str_from_vstr(&mp_type_bytes, &pkh); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is repeated, let's put it in a function. E.g. something like
mp_obj_t new_bytes_obj_from_byte_array_raise(const ByteArray *arr) {
assert(arr);
handle_err(arr);
...
}
/** | ||
* Type of information required by transaction signing process | ||
*/ | ||
enum MintlayerTokenTotalSupplyType { | ||
FIXED = 0; | ||
LOCKABLE = 1; | ||
UNLIMITED = 2; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also wrong comment?
Add new messages in the proto files for Mintlayer coin support, and handlers.