Standalone

Using Signatures

close button

Part II

Verifying Signatures

With the ability to sign messages, we can now work on the smart contract. To recap, the smart contract will:

  1. Hold funds (received during deployment).

  2. Transfer funds, aka blessing, to users (if they provide a corresponding signature from a Grandmaster).

  3. Promote a user to Grandmaster (if they provide a corresponding signature from a Grandmaster).

We will build a Grandmasters contract that supports the IGrandmasters interface.

Function

Description

grandmasters(address user) -> (bool)

Returns true if user is a grandmaster. Returns false otherwise.

acceptInvite(bytes signature)

Promotes msg.sender to grandmaster if the provided signature can be verified to be from a grandmaster. Reverts if signature is invalid.

receiveBlessing(uint256 amount, bytes signature)

Transfers amount of funds to the msg.sender if the provided signature can be verified to be from a grandmaster. Reverts if signature is invalid.

Like before, the signed messages to verify are as follows:

1. Invite a Grandmaster

Instruction for smart contract to promote an address to be a Grandmaster.

keccak256( "\x19Ethereum Signed Message:\n32" + keccak256("Invite{address}") )
  • address : Address of individual to be invited as a Grandmaster [20 bytes long]

2. Receive Blessing

Instruction for smart contract to transfer ETH to a recipient.

keccak256( "\x19Ethereum Signed Message:\n32" + keccak256("Bless{address}{amount}{ctr}") )
  • address : Address of recipient of blessing [20 bytes long]

  • amount : Amount of blessing (in wei) [32 bytes long]

  • ctr : Number of blessings the recipient has been given beforehand [4 bytes long].

Lastly, take note of these 2 pointers:

  • The contract's creator is by default, a Grandmaster.

  • The contract's constructor should be payable, so that the contract can receive funds.

Your Task

Complete Grandmasters.sol by implementing IGrandMasters.

Run tests in Questplay

Submit work in Questplay

The Grandmasters’ words are absolute. It is important for their followers to be able to discern them from lies.