Skip to content

Fix CI #11

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

Merged
merged 3 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,8 @@ jobs:

core_ui_comment:
name: Post comment with UI diff URLs
if: github.event_name == 'pull_request'
# if: github.event_name == 'pull_request'
if: false # Disabled for Mintlayer repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -776,7 +777,8 @@ jobs:

core_upload_emu:
name: Upload emulator binaries
if: github.event_name == 'schedule'
# if: github.event_name == 'schedule'
if: false # Disabled for Mintlayer repository
runs-on: ubuntu-latest
needs:
- core_emu
Expand All @@ -798,8 +800,9 @@ jobs:

core_upload_emu_branch:
name: Upload emulator binaries for the current branch
# Not building it for nightly CI
if: github.event_name != 'schedule'
# # Not building it for nightly CI
# if: github.event_name != 'schedule'
if: false # Disabled for Mintlayer repository
runs-on: ubuntu-latest
needs:
# Do not include ARM, they are only built on nightly
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/prebuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ jobs:
# or contain `[no changelog]` in the commit message.
changelog_check:
name: Changelog check
if: ${{ github.ref != 'main' && github.event_name == 'pull_request' }}
# if: ${{ github.ref != 'main' && github.event_name == 'pull_request' }}
if: false # Disabled for Mintlayer repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -97,7 +98,8 @@ jobs:
# Warn if core/embed/rust/Cargo.lock changed
cargolock_check:
name: Cargo.lock check
if: ${{ github.ref != 'main' && github.event_name == 'pull_request' }}
# if: ${{ github.ref != 'main' && github.event_name == 'pull_request' }}
if: false # Disabled for Mintlayer repository
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion common/protob/messages-management.proto
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ message Features {
Capability_Haptic = 21 [(bitcoin_only) = true];
Capability_BLE = 22 [(bitcoin_only) = true]; // Bluetooth Low Energy
Capability_NFC = 23 [(bitcoin_only) = true]; // Near Field Communications
Capability_Mintlayer = 24;
Capability_Mintlayer = 99;
}
}

Expand Down
4 changes: 3 additions & 1 deletion core/SConscript.firmware
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,9 @@ env.Replace(
ASPPFLAGS='$CFLAGS $CCFLAGS',
)

BYTECODE_OPTIMIZATION = {'0': '0', '1': '3'}[PYOPT]
# Mintlayer: the optimization level for the PYOPT=0 case was upped to 1, because otherwise some debuglink-enabled
# builds would fail due to flash overflow (e.g. it was the case for T3T1, where the overflow was about 3k bytes).
BYTECODE_OPTIMIZATION = {'0': '1', '1': '3'}[PYOPT]

env.Replace(
HEADERTOOL='headertool',
Expand Down
1 change: 1 addition & 0 deletions core/embed/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ test = [
"debug",
"glob",
"micropython",
"mintlayer",
"nrf",
"optiga",
"protobuf",
Expand Down
4 changes: 2 additions & 2 deletions core/embed/rust/src/mintlayer/input_commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ fn mintlayer_encode_input_commitment_v1_for_produce_block_from_stake_utxo_impl(
) -> Result<SighashInputCommitment, MintlayerErrorCode> {
let utxo = TxOutput::decode_all(&mut &encoded_utxo[..])
.map_err(|_| MintlayerErrorCode::InvalidEncodedUtxo)?;
let staker_balance = Amount::from_bytes_be(staker_balance_amount.as_ref())
.ok_or(MintlayerErrorCode::InvalidAmount)?;
let staker_balance =
Amount::from_bytes_be(staker_balance_amount).ok_or(MintlayerErrorCode::InvalidAmount)?;

Ok(SighashInputCommitment::ProduceBlockFromStakeUtxo {
utxo,
Expand Down
87 changes: 51 additions & 36 deletions core/embed/rust/src/mintlayer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
use crate::micropython::ffi;
use core::{
alloc::{GlobalAlloc, Layout},
ptr::null_mut,
};

use ml_common::{
AccountCommand, AccountCommandTag, AccountOutPoint, AccountSpending, Amount, Destination,
HashedTimelockContract, HtlcSecretHash, IsTokenFreezable, IsTokenUnfreezable, Metadata,
Expand Down Expand Up @@ -158,13 +152,13 @@ fn mintlayer_encode_token_account_command_input_impl(
AccountCommandTag::UnmintTokens => AccountCommand::UnmintTokens(token_id),
AccountCommandTag::LockTokenSupply => AccountCommand::LockTokenSupply(token_id),
AccountCommandTag::FreezeToken => {
let is_token_unfreezabe = IsTokenUnfreezable::decode_all(&mut data.as_ref())
let is_token_unfreezabe = IsTokenUnfreezable::decode_all(&mut &*data)
.map_err(|_| MintlayerErrorCode::InvalidIsTokenUnfreezable)?;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: all these changes are to pacify Clippy, which doesn't like the seemingly useless as_ref calls.

AccountCommand::FreezeToken(token_id, is_token_unfreezabe)
}
AccountCommandTag::UnfreezeToken => AccountCommand::UnfreezeToken(token_id),
AccountCommandTag::ChangeTokenAuthority => {
let destination = Destination::decode_all(&mut data.as_ref())
let destination = Destination::decode_all(&mut &*data)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
AccountCommand::ChangeTokenAuthority(token_id, destination)
}
Expand Down Expand Up @@ -273,7 +267,7 @@ fn mintlayer_encode_fill_order_account_command_input_impl(
);
let amount = parse_amount(coin_amount)?;

let destination = Destination::decode_all(&mut destination_bytes.as_ref())
let destination = Destination::decode_all(&mut &*destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let account_command = AccountCommand::FillOrder(order_id, amount, destination);
let tx_input = TxInput::AccountCommand(nonce, account_command);
Expand Down Expand Up @@ -316,7 +310,7 @@ fn mintlayer_encode_fill_order_v1_order_command_input_impl(
);
let amount = parse_amount(coin_amount)?;

let destination = Destination::decode_all(&mut destination_bytes.as_ref())
let destination = Destination::decode_all(&mut &*destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let order_command = OrderAccountCommand::FillOrder(order_id, amount, destination);
let tx_input = TxInput::OrderAccountCommand(order_command);
Expand Down Expand Up @@ -379,7 +373,7 @@ extern "C" fn mintlayer_encode_transfer_output(

let destination_bytes =
unsafe { core::slice::from_raw_parts(destination_data, destination_data_len as usize) };
let destination = match Destination::decode_all(&mut destination_bytes.as_ref()) {
let destination = match Destination::decode_all(&mut &*destination_bytes) {
Ok(destination) => destination,
Err(_) => return MintlayerErrorCode::InvalidDestination.into(),
};
Expand Down Expand Up @@ -412,7 +406,7 @@ extern "C" fn mintlayer_encode_lock_then_transfer_output(

let destination_bytes =
unsafe { core::slice::from_raw_parts(destination_data, destination_data_len as usize) };
let destination = match Destination::decode_all(&mut destination_bytes.as_ref()) {
let destination = match Destination::decode_all(&mut &*destination_bytes) {
Ok(destination) => destination,
Err(_) => return MintlayerErrorCode::InvalidDestination.into(),
};
Expand Down Expand Up @@ -520,11 +514,11 @@ fn mintlayer_encode_create_stake_pool_output_impl(
.map_err(|_| MintlayerErrorCode::WrongHashSize)?,
);
let pledge = parse_amount(pledge_coin_amount)?;
let staker = Destination::decode_all(&mut staker_destination_bytes.as_ref())
let staker = Destination::decode_all(&mut &*staker_destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let vrf_public_key = VRFPublicKeyHolder::decode_all(&mut vrf_public_key.as_ref())
let vrf_public_key = VRFPublicKeyHolder::decode_all(&mut &*vrf_public_key)
.map_err(|_| MintlayerErrorCode::InvalidVrfPublicKey)?;
let decommission_key = Destination::decode_all(&mut decommission_destination_bytes.as_ref())
let decommission_key = Destination::decode_all(&mut &*decommission_destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let cost_per_block = parse_amount(cost_per_block_coin_amount)?;
let txo = TxOutput::CreateStakePool(
Expand Down Expand Up @@ -556,7 +550,7 @@ extern "C" fn mintlayer_encode_produce_from_stake_output(

let destination_bytes =
unsafe { core::slice::from_raw_parts(destination_data, destination_data_len as usize) };
let destination = match Destination::decode_all(&mut destination_bytes.as_ref()) {
let destination = match Destination::decode_all(&mut &*destination_bytes) {
Ok(destination) => destination,
Err(_) => return MintlayerErrorCode::InvalidDestination.into(),
};
Expand All @@ -581,7 +575,7 @@ extern "C" fn mintlayer_encode_create_delegation_id_output(

let destination_bytes =
unsafe { core::slice::from_raw_parts(destination_data, destination_data_len as usize) };
let destination = match Destination::decode_all(&mut destination_bytes.as_ref()) {
let destination = match Destination::decode_all(&mut &*destination_bytes) {
Ok(destination) => destination,
Err(_) => return MintlayerErrorCode::InvalidDestination.into(),
};
Expand Down Expand Up @@ -663,7 +657,7 @@ fn mintlayer_encode_issue_fungible_token_output_impl(
) -> Result<TxOutput, MintlayerErrorCode> {
let token_ticker = token_ticker.to_vec();
let metadata_uri = metadata_uri.to_vec();
let authority = Destination::decode_all(&mut authority_bytes.as_ref())
let authority = Destination::decode_all(&mut &*authority_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let is_freezable = IsTokenFreezable::from_u8(is_freezable)
.ok_or(MintlayerErrorCode::InvalidIsTokenFreezable)?;
Expand Down Expand Up @@ -751,6 +745,7 @@ extern "C" fn mintlayer_encode_issue_nft_output(
handle_err_or_encode(res)
}

#[allow(clippy::too_many_arguments)]
fn mintlayer_encode_issue_nft_output_impl(
token_id: &[u8],
creator_data_len: u32,
Expand Down Expand Up @@ -785,7 +780,7 @@ fn mintlayer_encode_issue_nft_output_impl(
let additional_metadata_uri = additional_metadata_uri.to_vec();
let media_uri = media_uri.to_vec();
let media_hash = media_hash.to_vec();
let destination = Destination::decode_all(&mut destination_bytes.as_ref())
let destination = Destination::decode_all(&mut &*destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let issuance = NftIssuance::V0(NftIssuanceV0 {
metadata: Metadata {
Expand Down Expand Up @@ -873,9 +868,9 @@ fn mintlayer_encode_htlc_output_impl(
lock_amount: u64,
value: OutputValue,
) -> Result<TxOutput, MintlayerErrorCode> {
let refund_key = Destination::decode_all(&mut refund_destination_bytes.as_ref())
let refund_key = Destination::decode_all(&mut &*refund_destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let spend_key = Destination::decode_all(&mut spend_destination_bytes.as_ref())
let spend_key = Destination::decode_all(&mut &*spend_destination_bytes)
.map_err(|_| MintlayerErrorCode::InvalidDestination)?;
let secret_hash = HtlcSecretHash(
hash.try_into()
Expand Down Expand Up @@ -936,7 +931,7 @@ extern "C" fn mintlayer_encode_create_order_output(

let destination_bytes =
unsafe { core::slice::from_raw_parts(destination_data, destination_data_len as usize) };
let destination = match Destination::decode_all(&mut destination_bytes.as_ref()) {
let destination = match Destination::decode_all(&mut &*destination_bytes) {
Ok(destination) => destination,
Err(_) => return MintlayerErrorCode::InvalidDestination.into(),
};
Expand All @@ -962,27 +957,32 @@ extern "C" fn mintlayer_encode_compact_length(length: u32) -> ByteArray {
encode_to_byte_array(&len)
}

struct CustomAllocator;
// Note: can't use this allocator globally in tests, because allocations start
// to happen too early (before main).
#[cfg(not(test))]
mod global_alloc {
use core::alloc::{GlobalAlloc, Layout};

use crate::micropython::ffi::{gc_alloc, gc_free};

struct CustomAllocator;

unsafe impl GlobalAlloc for CustomAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe {
let ptr_void = ffi::gc_alloc(layout.size(), 0); // Call ffi::gc_alloc
if ptr_void.is_null() {
return null_mut();
unsafe impl GlobalAlloc for CustomAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe { gc_alloc(layout.size(), 0).cast() }
}

unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
unsafe {
gc_free(ptr.cast());
}
ptr_void as *mut u8 // Cast the pointer to *mut u8
}
}

unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
// Implement deallocation logic here if needed
}
#[global_allocator]
static GLOBAL_ALLOCATOR: CustomAllocator = CustomAllocator;
}

#[global_allocator]
static GLOBAL_ALLOCATOR: CustomAllocator = CustomAllocator;

fn handle_err_or_encode<T: Encode>(x: Result<T, MintlayerErrorCode>) -> ByteArray {
match x {
Ok(value) => encode_to_byte_array(&value),
Expand All @@ -1005,3 +1005,18 @@ fn encode_to_byte_array<T: Encode>(x: &T) -> ByteArray {
len_or_err: LenOrError { len },
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn basic() {
let hash: [u8; 32] = [0; 32];
let result = mintlayer_encode_utxo_input(hash.as_ptr(), 32, 123, 1);
assert!(result.data != core::ptr::null());

let result = mintlayer_encode_utxo_input(hash.as_ptr(), 31, 123, 1);
assert!(result.data == core::ptr::null());
}
}
4 changes: 2 additions & 2 deletions core/embed/upymod/modtrezormintlayer/modtrezormintlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include TREZOR_BOARD

// #if MICROPY_PY_TREZORMINTLAYER
#if !BITCOIN_ONLY

#include "modtrezormintlayer-input-comm.h"
#include "modtrezormintlayer.h"
Expand Down Expand Up @@ -120,4 +120,4 @@ const mp_obj_module_t mp_module_trezormintlayer = {

MP_REGISTER_MODULE(MP_QSTR_trezormintlayer, mp_module_trezormintlayer);

// #endif // MICROPY_PY_TREZORMINTLAYER
#endif // !BITCOIN_ONLY
24 changes: 12 additions & 12 deletions core/embed/upymod/modtrezormintlayer/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@ void handle_err(ByteArray *res) {

switch (res->len_or_err.err) {
case WrongHashSize:
mp_raise_ValueError("Invalid hash size");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid hash size"));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI: these changes fix compilation after the merge from upstream. Technically they should be part of #12 but I decided to put them here for easier review.

break;
case InvalidUtxoType:
mp_raise_ValueError("Invalid UTXO type");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid UTXO type"));
break;
case InvalidAmount:
mp_raise_ValueError("Invalid amount");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid amount"));
break;
case InvalidAccountCommand:
mp_raise_ValueError("Invalid account command");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid account command"));
break;
case InvalidDestination:
mp_raise_ValueError("Invalid destination");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid destination"));
break;
case InvalidIsTokenUnfreezable:
mp_raise_ValueError("Invalid token unfreezable flag");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid token unfreezable flag"));
break;
case InvalidIsTokenFreezable:
mp_raise_ValueError("Invalid token freezable flag");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid token freezable flag"));
break;
case InvalidVrfPublicKey:
mp_raise_ValueError("Invalid VRF public key");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid VRF public key"));
break;
case InvalidPublicKey:
mp_raise_ValueError("Invalid public key");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid public key"));
break;
case InvalidOutputTimeLock:
mp_raise_ValueError("Invalid output time lock");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid output time lock"));
break;
case InvalidTokenTotalSupply:
mp_raise_ValueError("Invalid token total supply");
mp_raise_ValueError(MP_ERROR_TEXT("Invalid token total supply"));
break;
default:
mp_raise_ValueError("Unknown error");
mp_raise_ValueError(MP_ERROR_TEXT("Unknown error"));
break;
}
}
2 changes: 1 addition & 1 deletion core/src/trezor/enums/Capability.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/src/trezor/enums/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion python/src/trezorlib/messages.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading