Skip to main content

Exam



Question 1#

Which notions are defined inside the smart contract?











Question 2#

What is returned by the execution of a smart contract?











Question 3#

Consider the following Michelson smart contract:

parameter nat;
storage nat;
code { DUP; CAR; DIP { CDR }; ADD; NIL operation; PAIR }

What is the stack at the beginning of the execution (considering parameter value is 2 and storage value is 5)?

Check the right answer.


![](../../static/img/michelson/QCM_3_response_A.svg)

![](../../static/img/michelson/QCM_3_response_B.svg)


![](../../static/img/michelson/QCM_3_response_D.svg)


Question 4#

Consider the following Michelson smart contract.

parameter nat;
storage nat;
code { DUP; CAR; DIP { CDR }; ADD; NIL operation; PAIR }

Considering that the parameter value is 1 and that the storage value is 1, what will be the output of the execution?








Question 5#

Consider the following Michelson smart contract:

parameter (or (pair %assign address nat) (nat %global)) ;
storage (pair (big_map %owners address nat) (nat %value)) ;
code { DUP ;
CDR ;
SWAP ;
CAR ;
IF_LEFT
{ SWAP ;
DUP ;
CDR ;
DUG 2 ;
CAR ;
SWAP ;
UNPAIR ;
DIP { SOME };
UPDATE ;
PAIR ;
NIL operation ;
PAIR
}
{ SWAP ; CAR ; PAIR ; NIL operation ; PAIR } }

What are the possible invocations of this smart contract?














Question 6#

Consider the following Michelson smart contract storage:

storage (pair (pair (set %participants nat) (pair (nat %age) (string %name))) (pair (big_map %owners address nat) (nat %value)));

Notice that the storage is composed of nested pairs. Let's consider that the storage is the top element of the stack. Which instruction can be used to retrieve the big_map part of the storage?










Question 7#

Consider the following smart contract that allows to increment or decrement an integer counter:

parameter (or (int %increment) (int %decrement)) ;
storage int ;
code {
DUP ;
CDR ;
SWAP ;
CAR ;
XXXXX
{ SWAP ; SUB }
{ ADD } ;
NIL operation ;
PAIR }

The XXXXX instruction must be replaced by a conditional instruction. Which instruction should be used?










Question 8#

The following contract is incomplete:

parameter (or (pair %assign string nat) (string %remove)) ;
storage (big_map string nat) ;
code { DUP ;
CDR ;
SWAP ;
CAR ;
IF_LEFT
{ UNPAIR ; DIP { SOME } }
{ XXXXXXX };
UPDATE ;
NIL operation ;
PAIR
}

Notice that the storage is a big_map and that the parameter allows two possible invocations: "assign" and "remove".

The "assign" entrypoint takes two arguments ( a "key" as a string and a "value" as a nat) set in a pair. The goal of the "assign" entrypoint is to modify the storage (the big_map) by assigning the given "value" to the given "key".

The "remove" entrypoint takes a single argument (a "key" as a string). The goal of the "remove" entrypoint is to modify the storage by removing the given "key" from the big_map.

Complete the missing "XXXXXXX" sequence of instructions according to the previously-mentioned statements.
















Question 9#

Consider the following "QCM_9.tz" smart contract.

parameter int ;
storage (pair (set int) bool) ;
code {
DUP ; CDAR ; SWAP ; CAR ; DIP { DUP } ;
MEM ;
SWAP ;
PAIR ;
NIL operation ;
PAIR }

We invoke this contract with the following command:

tezos-client run script QCM_9.tz on storage 'Pair {1;2;3;4} True' and input '5'

Notice that this command defines the initial storage state as Pair {1;2;3;4} True and the parameter as 5.

What is the resulting storage state?









Question 10#

Consider the following "QCM_10.tz" smart contract:

parameter unit ;
storage (map string nat) ;
code {
CDR ;
MAP { CDR ;
DUP ;
PUSH nat 2 ;
SWAP ;
EDIV ;
IF_NONE
{ FAIL }
{ CDR ;
INT ;
IFEQ
{}
{ PUSH nat 2; MUL}
}
} ;
NIL operation ;
PAIR }

We invoke this contract with the following command:

tezos-client run script QCM_10.tz on storage '{ Elt "alice" 1; Elt "bob" 2; Elt "carin" 3 }' and input 'Unit'

Notice that this command defines the initial storage state as { Elt "alice" 1; Elt "bob" 2; Elt "carin" 3 } and the parameter as Unit.

What is the resulting storage state ?


![](../../static/img/michelson/QCM_10_123.svg)

![](../../static/img/michelson/QCM_10_143.svg)

![](../../static/img/michelson/QCM_10_146.svg)

![](../../static/img/michelson/QCM_10_126.svg)

![](../../static/img/michelson/QCM_10_223.svg)

![](../../static/img/michelson/QCM_10_243.svg)


![](../../static/img/michelson/QCM_10_246.svg)

Last updated on by Aymeric BETHENCOURT