Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Multi-signature wallet concept in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Multi-signature Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this multi-signature wallet approval count?
Consider a multi-signature wallet contract where 3 owners must approve a transaction. The code below simulates approvals. What is the final approval count?
Blockchain / Solidity
approvals = {'owner1': True, 'owner2': False, 'owner3': True}
approval_count = sum(1 for approved in approvals.values() if approved)
print(approval_count)
A1
B2
C3
D0
Attempts:
2 left
💡 Hint
Count how many owners have True as their approval status.
🧠 Conceptual
intermediate
1:30remaining
Which statement best describes a multi-signature wallet?
Choose the correct description of a multi-signature wallet.
AA wallet that automatically sends funds to multiple recipients.
BA wallet that stores multiple cryptocurrencies in one address.
CA wallet that can only be accessed by one owner at a time.
DA wallet that requires multiple private keys to authorize a transaction.
Attempts:
2 left
💡 Hint
Think about how multiple people approve spending.
🔧 Debug
advanced
2:30remaining
What error does this multi-signature wallet code raise?
This Python-like pseudocode simulates a multi-signature wallet transaction approval. What error occurs when running it?
Blockchain / Solidity
owners = ['Alice', 'Bob', 'Charlie']
approvals = {'Alice': True, 'Bob': True}
required = 3
count = sum(approvals[owner] for owner in owners)
if count >= required:
    print('Transaction approved')
else:
    print('Transaction pending')
AKeyError because 'Charlie' is missing in approvals dictionary
BTypeError because sum cannot add booleans
CNo error, prints 'Transaction approved'
DIndexError due to list access
Attempts:
2 left
💡 Hint
Check if all owners have approval entries.
🚀 Application
advanced
3:00remaining
How many transactions can be approved with this multi-signature setup?
A multi-signature wallet requires 2 out of 3 owners to approve a transaction. Given the following approvals, how many transactions are approved?
Blockchain / Solidity
transactions = [
  {'id': 1, 'approvals': {'Alice': True, 'Bob': True, 'Charlie': False}},
  {'id': 2, 'approvals': {'Alice': False, 'Bob': True, 'Charlie': True}},
  {'id': 3, 'approvals': {'Alice': False, 'Bob': False, 'Charlie': True}}
]
required = 2
approved_count = 0
for tx in transactions:
    count = sum(tx['approvals'].values())
    if count >= required:
        approved_count += 1
print(approved_count)
A2
B3
C1
D0
Attempts:
2 left
💡 Hint
Count transactions where approvals are at least 2.
📝 Syntax
expert
3:00remaining
Which option correctly defines a multi-signature wallet approval function in Solidity?
Select the correct Solidity function syntax that checks if a transaction has enough approvals.
Blockchain / Solidity
function isApproved(uint txId) public view returns (bool) {
    uint count = 0;
    for (uint i = 0; i < owners.length; i++) {
        if (approvals[txId][owners[i]]) {
            count++;
        }
    }
    return count >= required;
}
A
function isApproved(uint txId) public view returns bool {
    uint count = 0;
    for (uint i = 0; i &lt; owners.length; i++) {
        if (approvals[txId][owners[i]]) {
            count++;
        }
    }
    return count &gt;= required;
}
B
function isApproved(uint txId) public returns (bool) {
    uint count = 0;
    for (uint i = 0; i &lt;= owners.length; i++) {
        if (approvals[txId][owners[i]]) {
            count++;
        }
    }
    return count &gt;= required;
}
C
function isApproved(uint txId) public view returns (bool) {
    uint count = 0;
    for (uint i = 0; i &lt; owners.length; i++) {
        if (approvals[txId][owners[i]]) {
            count++;
        }
    }
    return count &gt;= required;
}
D
function isApproved(uint txId) public view returns (bool) {
    uint count = 0;
    for (uint i = 0; i &lt; owners.length; i++) {
        if (approvals[txId][owners[i]] == true) {
            count = count + 1;
        }
    }
    return count &gt;= required;
}
Attempts:
2 left
💡 Hint
Check for correct function signature, loop bounds, and syntax.

Practice

(1/5)
1. What is the main purpose of a multi-signature wallet in blockchain?
easy
A. To require multiple approvals before spending funds
B. To speed up transaction processing
C. To store private keys on a single device
D. To allow unlimited spending by one user

Solution

  1. Step 1: Understand the multi-signature wallet concept

    A multi-signature wallet requires more than one person to approve a transaction before it can be executed.
  2. Step 2: Identify the main purpose

    This setup protects funds by preventing a single user from spending money alone, increasing security.
  3. Final Answer:

    To require multiple approvals before spending funds -> Option A
  4. Quick Check:

    Multi-signature = multiple approvals [OK]
Hint: Multi-signature means multiple people must approve [OK]
Common Mistakes:
  • Thinking it speeds up transactions
  • Believing one user controls all funds
  • Confusing it with single-key wallets
2. Which of the following is the correct way to define a multi-signature wallet threshold in Solidity?
easy
A. bool threshold = true;
B. uint8 threshold = '2';
C. string threshold = 2;
D. uint8 threshold = 1;

Solution

  1. Step 1: Identify correct data type for threshold

    The threshold is a number representing how many signatures are needed, so an unsigned integer like uint8 is appropriate.
  2. Step 2: Check syntax correctness

    Assigning a number directly to uint8 is correct. Using quotes or wrong types causes errors.
  3. Final Answer:

    uint8 threshold = 1; -> Option D
  4. Quick Check:

    Threshold is a number, use uint8 [OK]
Hint: Threshold is a number, use uint type without quotes [OK]
Common Mistakes:
  • Using quotes around numbers
  • Assigning string type to threshold
  • Using boolean type for threshold
3. Given this Solidity snippet for a multi-signature wallet, what will be the value of isApproved after calling approveTransaction(1, msg.sender) if the threshold is 2 and only one approval is made?
mapping(uint => mapping(address => bool)) approvals;
uint8 threshold = 2;

function approveTransaction(uint txId, address approver) public {
  approvals[txId][approver] = true;
}

function isApproved(uint txId) public view returns (bool) {
  uint count = 0;
  for (uint i = 0; i < owners.length; i++) {
    if (approvals[txId][owners[i]]) {
      count++;
    }
  }
  return count >= threshold;
}
medium
A. true
B. false
C. Compilation error
D. Undefined behavior

Solution

  1. Step 1: Understand approval counting logic

    The function counts how many owners approved the transaction and compares it to the threshold.
  2. Step 2: Analyze given scenario

    Only one approval is made but threshold is 2, so count is 1 which is less than 2.
  3. Final Answer:

    false -> Option B
  4. Quick Check:

    Approvals < threshold = false [OK]
Hint: Approval count must meet threshold to be true [OK]
Common Mistakes:
  • Assuming one approval is enough
  • Ignoring threshold comparison
  • Confusing approval mapping structure
4. Identify the bug in this Solidity function for approving transactions in a multi-signature wallet:
function approveTransaction(uint txId) public {
  approvals[txId][msg.sender] = true;
  if (isApproved(txId)) {
    executeTransaction(txId);
  }
}

function isApproved(uint txId) public view returns (bool) {
  uint count = 0;
  for (uint i = 0; i <= owners.length; i++) {
    if (approvals[txId][owners[i]]) {
      count++;
    }
  }
  return count >= threshold;
}
medium
A. Missing event emission after approval
B. approveTransaction should be external, not public
C. Loop condition should be < instead of <=
D. executeTransaction should not be called inside approveTransaction

Solution

  1. Step 1: Check the for loop boundary

    The loop uses i <= owners.length, which causes out-of-bounds access because array indices go from 0 to length-1.
  2. Step 2: Correct the loop condition

    Changing to i < owners.length prevents accessing invalid index and runtime errors.
  3. Final Answer:

    Loop condition should be < instead of <= -> Option C
  4. Quick Check:

    Array index out of bounds fixed by < [OK]
Hint: Array loops use < length, not <= length [OK]
Common Mistakes:
  • Using <= in loops causing errors
  • Ignoring array index limits
  • Thinking event emission fixes logic bugs
5. You want to create a multi-signature wallet that requires 3 out of 5 owners to approve a transaction. Which approach correctly enforces this rule in Solidity?
mapping(uint => mapping(address => bool)) approvals;
address[5] owners;
uint8 threshold = 3;

function executeTransaction(uint txId) public {
  uint count = 0;
  for (uint i = 0; i < owners.length; i++) {
    if (approvals[txId][owners[i]]) {
      count++;
    }
  }
  if (count >= threshold) {
    // execute the transaction
  } else {
    revert("Not enough approvals");
  }
}
hard
A. This code correctly enforces the 3-of-5 approval rule
B. The threshold should be set to 5 to require all owners
C. The loop should iterate over approvals, not owners
D. Revert should be replaced with a simple return statement

Solution

  1. Step 1: Analyze the approval counting logic

    The code counts how many owners approved the transaction by checking the approvals mapping for each owner.
  2. Step 2: Check threshold enforcement

    If the count is at least the threshold (3), the transaction executes; otherwise, it reverts with an error.
  3. Final Answer:

    This code correctly enforces the 3-of-5 approval rule -> Option A
  4. Quick Check:

    Count approvals >= threshold = enforce rule [OK]
Hint: Count approvals, compare with threshold, revert if not met [OK]
Common Mistakes:
  • Setting threshold incorrectly
  • Looping over wrong data structure
  • Using return instead of revert for errors