Skip to content

Commit 052cffe

Browse files
author
vlad
committed
machine_id as string (fixes)
1 parent 87c8533 commit 052cffe

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

cosmwasm/enclaves/execute/src/registration/offchain.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,13 @@ fn is_msg_machine_id(msg_in_block: &[u8], machine_id: &[u8]) -> bool {
724724
trace!("*** block msg: {:?}", hex::encode(msg_in_block));
725725

726726
// we expect a message of the form:
727-
// 0a 3d (addr, len=45 bytes)
727+
// 0a 2d (addr, len=45 bytes)
728728
// 10 (proposal-id, varible length)
729-
// 1a 14 (machine_id 20 bytes)
729+
// 1a 28 (machine_id 40 bytes)
730730

731731
let msg_len = msg_in_block.len();
732732

733-
if msg_len < 71 {
733+
if msg_len < 91 {
734734
trace!("len mismatch: {}", msg_in_block.len());
735735
return false;
736736
}
@@ -745,14 +745,14 @@ fn is_msg_machine_id(msg_in_block: &[u8], machine_id: &[u8]) -> bool {
745745
return false;
746746
}
747747

748-
let offs = msg_len - 22;
748+
let offs = msg_len - 42;
749749

750-
if &msg_in_block[offs..offs + 2] != [0x1a, 0x14].as_slice() {
750+
if &msg_in_block[offs..offs + 2] != [0x1a, 0x28].as_slice() {
751751
trace!("wrong sub3");
752752
return false;
753753
}
754754

755-
if &msg_in_block[offs + 2..offs + 22] != machine_id {
755+
if &msg_in_block[offs + 2..offs + 42] != machine_id {
756756
trace!("wrong mrenclave");
757757
return false;
758758
}
@@ -798,7 +798,9 @@ pub unsafe extern "C" fn ecall_onchain_approve_machine_id(
798798
let proof = calculate_machine_id_evidence(machine_id);
799799

800800
if is_on_chain {
801-
if !check_machine_id_in_block(machine_id) {
801+
let machine_id_str = hex::encode(machine_id);
802+
803+
if !check_machine_id_in_block(machine_id_str.as_bytes()) {
802804
error!("machine ID not approved");
803805
return sgx_types::sgx_status_t::SGX_ERROR_UNEXPECTED;
804806
}

x/compute/client/cli/tx.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,10 @@ Examples:
648648

649649
func UpdateMachineWhitelistCmd() *cobra.Command {
650650
cmd := &cobra.Command{
651-
Use: "update-machine-whitelist [proposal-id] [machine-ids-file]",
651+
Use: "update-machine-whitelist [proposal-id] [machine-id]",
652652
Short: "Update machine whitelist after governance approval",
653653
Long: `Execute machine whitelist update after governance proposal passes.
654-
Machine IDs must match the approved proposal exactly.
655-
656-
Machine IDs file format (JSON):
657-
{
658-
"machine_ids": [
659-
"01507c9577896bc1afde972d67f1fd53af1a8da",
660-
"a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6"
661-
]
662-
}
663-
664-
Each machine ID must be exactly 20 bytes.`,
654+
Machine ID must match the approved proposal exactly.`,
665655
Args: cobra.ExactArgs(2),
666656
RunE: func(cmd *cobra.Command, args []string) error {
667657
clientCtx, err := client.GetClientTxContext(cmd)
@@ -674,11 +664,8 @@ Each machine ID must be exactly 20 bytes.`,
674664
return fmt.Errorf("invalid proposal ID: %w", err)
675665
}
676666

677-
// Read machine IDs from file
678-
machineId, err := hex.DecodeString(args[1])
679-
if err != nil {
680-
return err
681-
}
667+
// Read machine ID
668+
machineId := args[1]
682669

683670
msg := &types.MsgUpdateMachineWhitelist{
684671
Sender: clientCtx.GetFromAddress().String(),

x/compute/internal/keeper/ante.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (a *CountTXDecorator) validateUpdateMachineWhitelist(ctx sdk.Context, msgUp
147147
return err
148148
}
149149

150-
if !bytes.Equal(msgUpdateWhitelist.MachineId, updateMachineWhitelistProposalMsg.MachineId) {
150+
if msgUpdateWhitelist.MachineId != updateMachineWhitelistProposalMsg.MachineId {
151151
return sdkerrors.ErrInvalidRequest.Wrapf("machine id %s does not match the proposal %s", msgUpdateWhitelist.MachineId, updateMachineWhitelistProposalMsg.MachineId)
152152
}
153153

x/compute/internal/keeper/msg_server.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package keeper
22

33
import (
44
"context"
5+
"encoding/hex"
56
"fmt"
67

78
errorsmod "cosmossdk.io/errors"
@@ -351,7 +352,11 @@ func (m msgServer) UpdateMachineWhitelist(goCtx context.Context, msg *types.MsgU
351352

352353
store := m.keeper.storeService.OpenKVStore(ctx)
353354

354-
id := msg.MachineId
355+
id, err := hex.DecodeString(msg.MachineId)
356+
if err != nil {
357+
return nil, err
358+
}
359+
355360
{
356361
proof := [32]byte{}
357362
if err := api.OnApproveMachineID(id, &proof, true); err != nil {

x/compute/internal/types/msg.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ func (msg MsgUpdateMachineWhitelistProposal) ValidateBasic() error {
332332
return errorsmod.Wrap(err, "invalid authority")
333333
}
334334

335-
if len(msg.MachineId) != 20 {
336-
return errorsmod.Wrap(ErrInvalid, "machine_id must be 20 bytes")
335+
if len(msg.MachineId) != 40 {
336+
return errorsmod.Wrap(ErrInvalid, "machine_id must be 40 characters")
337337
}
338338

339339
return nil
@@ -368,8 +368,8 @@ func (msg MsgUpdateMachineWhitelist) ValidateBasic() error {
368368
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "proposal ID cannot be zero")
369369
}
370370

371-
if len(msg.MachineId) != 20 {
372-
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "machine ID must be 20 bytes")
371+
if len(msg.MachineId) != 40 {
372+
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "machine ID must be 40 characters")
373373
}
374374

375375
return nil

0 commit comments

Comments
 (0)