Skip to content
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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Feature/mintlayer pk #1

wants to merge 22 commits into from

Conversation

OBorce
Copy link
Collaborator

@OBorce OBorce commented May 15, 2024

Add new messages in the proto files for Mintlayer coin support, and handlers.

@azarovh
Copy link
Member

azarovh commented Aug 6, 2024

I wouldn't merge this to master but rather created a separate branch like mintlayer-master and merge features there. This way we can keep it clean and isolated and when we decide to update trezor version we will pull to master and rebase our master. Otherwise it could become a mess very quickly. Makes sense?

One thing to consider is that CI might not work for "our" master.

Copy link

@ImplOfAnImpl ImplOfAnImpl left a 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/modtrezorcrypto/modtrezorcrypto-bip32.h Outdated Show resolved Hide resolved
rust/trezor-client/src/error.rs Outdated Show resolved Hide resolved
rust/trezor-client/src/error.rs Outdated Show resolved Hide resolved
core/src/apps/bitcoin/sign_tx/layout.py Outdated Show resolved Hide resolved
core/src/apps/bitcoin/sign_tx/layout.py Outdated Show resolved Hide resolved
core/src/apps/workflow_handlers.py Outdated Show resolved Hide resolved
core/src/trezor/crypto/bech32.py Outdated Show resolved Hide resolved
Comment on lines 166 to 181
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

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?

Copy link
Collaborator Author

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.

core/src/trezor/crypto/bech32.py Outdated Show resolved Hide resolved
@OBorce OBorce force-pushed the feature/mintlayer-pk branch 15 times, most recently from a7ca54f to 941d641 Compare September 12, 2024 15:26
@OBorce OBorce changed the base branch from master to main September 12, 2024 16:32
@OBorce OBorce force-pushed the feature/mintlayer-pk branch 5 times, most recently from 2d02cde to 86275f8 Compare September 15, 2024 17:44
@OBorce OBorce force-pushed the feature/mintlayer-pk branch 5 times, most recently from 79e901f to 180e245 Compare September 17, 2024 18:36
Copy link

@ImplOfAnImpl ImplOfAnImpl left a 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

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

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

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

Comment on lines +393 to +394
required MintlayerTokenTotalSupplyType type = 1; // the amount to stake
optional bytes fixed_amount = 2; // the amount to stake

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong comments

Comment on lines +347 to +353
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

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.

Comment on lines +1245 to +1246
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)]
struct StakePoolData {

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.

Comment on lines +76 to +81
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];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Plz use a miningful name instead of "pkh" (it's not a public key hash here).
  2. Use memcpy instead of looping.

Same in other places.

Comment on lines +101 to +105
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");
}

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.

Comment on lines +112 to +121
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);

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);
    ...
}

Comment on lines +380 to +388
/**
* Type of information required by transaction signing process
*/
enum MintlayerTokenTotalSupplyType {
FIXED = 0;
LOCKABLE = 1;
UNLIMITED = 2;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also wrong comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants