ModelQuestionPaper2
ModelQuestionPaper2
interface MoblieOS { }
interface PowerFullChipset { }
CSIT6000Q (L1) Final Exam Question Paper - Page 5 of 24 16/12/2023
f1 = new uint[](10);
f2 = f1;
}
}
contract contract_A {
uint private AX;
uint public BX;
string internal Cstr;
constructor() {
BX=24;
}
function increment(uint Dr) private pure returns(uint){
return Dr+1;
}
function updateAX(uint Dr) public{
AX=Dr;
}
function getAX() public view returns(uint){
return AX;
}
function setCstr(string memory _Cstr) public;
function getCstr() public view returns(string memory);
}
cA.updateAX(25);
return (cA.getAX(), cA.getCstr());
}
}
contract sender {
function setInput(uint _input) public payable {
address _receiver=0x5B38Da6a701c568545dCfcB03FcB875f56beddC4;
_receiver.transfer(100);
}
}
(d) (5 points) Which statements about the following contract are true?
pragma solidity >=0.8.2 <0.9.0;
abstract contract Book{
string internal material=’papyrus’;
constructor () {}
}
contract Encyclopedia is Book{
constructor () {
}
function getMaterial() public view returns(string memory){
return super.material;
}
}
B. 2 only
C. 2 and 5.
D. 2 and 6.
E. 2 and 3.
F. 1 and 4.
Solution:
(e) (5 points) The contract MathBase has a modifier to check if the input number is
divisible by 3, 5 and 7. Is it possible to override the modifier? If possible, then
complete the following code of MathBase and MathDivisor. If not possible, then
complete the following code of MathBase only.
contract MathBase {
modifier exactDividedBy2And3(uint _a) ------------------
}
contract MathDivisor is MathBase{
modifier exactDividedBy2And3(uint _a) ------------------
(f) (6 points) Will the following code compile? If not, correct the code. Please write
the expected event output when the following calls are made:
• roarCall(-1)
• roarCall(0)
• roarCall(1)
• roarCall(2)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract BigCat{
event BigCatRoar(string message);
function roar(uint level) public pure returns (string memory result){
require(level >= 0, "Not a valid Roar");
require(level != 1, "Meow is not Roar");
emit BigCatRoar("Valid Roar of Big Cat");
return "Valid Roar of Big Cat";
}
}
contract Lion is BigCat{
event LionRoar(string message);
BigCat public bigCat;
constructor() {
CSIT6000Q (L1) Final Exam Question Paper - Page 10 of 24 16/12/2023
Solution:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract BigCat{
event BigCatRoar(string message);
}
contract Lion is BigCat{
event LionRoar(string message);
BigCat public bigCat;
CSIT6000Q (L1) Final Exam Question Paper - Page 11 of 24 16/12/2023
Solution:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
CSIT6000Q (L1) Final Exam Question Paper - Page 13 of 24 16/12/2023
(b) (10 points) Is the following smart contract safe? If not, what type of vulnerabilities
are associated with it?
1 contract Trader {
2 TokenSale tokenSale = new TokenSale () ; // Internal Contract defined
at line in the same file
3 function combination () {
4 tokenSale.buyTokensWithWei () ;
5 tokenSale . buyTokens ( beneficiary ) ;
6 }
7 }
8 contract TokenSale {
9 TokenOnSale tokenOnSale ; // External Contract
10 ...
11 function set ( address _add ) {
12 tokenOnSale = TokenOnSale ( _add ) ;
13 }
14 function buyTokens ( address beneficiary ) {
15 if ( starAllocationToTokenSale > 0) {
16 tokenOnSale.mint ( beneficiary , tokens ) ;
17 }
18 }
19 function buyTokensWithWei () onlyTrader {
20 wallet.transfer ( weiAmount ) ;
21 }
22 }
Solution:
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
CSIT6000Q (L1) Final Exam Question Paper - Page 14 of 24 16/12/2023
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
select block_date,
transaction_count,
sum(transaction_count) over (order by block_date) as
accumulate_transaction_count
from lz_send_summary
• blockchain
• source chain id
• source chain name
• destination chain id
• destination chain name
• tx hash
• block number
• endpoint contract
CSIT6000Q (L1) Final Exam Question Paper - Page 16 of 24 16/12/2023
• block time
• trace address
• adapter params
• refund address
• zro payment address
• user address
• transaction contract
• source bridge contract
• destination bridge contract
• transfer type
• currency symbol
• currency contract
• amount usd
• amount original
• amount raw
Solution:
-
-
CSIT6000Q (L1) Final Exam Question Paper - Page 17 of 24 16/12/2023
(b) (3 points) Implement the concatenate function which takes three strings as input
and returns the concatenated string.
function concatThreeString(................).......................{
(c) (5 points) Implement the substring function, it takes three input - the string, start-
ing index of the substring and ending index of the substring.
function substring(.........................).........................{
CSIT6000Q (L1) Final Exam Question Paper - Page 18 of 24 16/12/2023
(d) (5 points) Implement the charAt function which accepts one string and one index
value. It returns the char present at index of the string.
function charAt(..........................)........................{
(e) (5 points) Implement the replace function which accepts one string, one letter of
the alphabet, and one position value. It will replace the letter at a specific position
of the first string.
function replace(.....................) ..................... {
contract MerkleTree {
// ROOT
// / \
CSIT6000Q (L1) Final Exam Question Paper - Page 19 of 24 16/12/2023
// H1-2 H3-4
// / \ / \
// H1 H2 H3 H4
// | | | |
// TX1 TX2 TX3 TX4
bytes32[] public hashes;
string[4] transactions = [
"TX1: Sherlock -> John",
"TX2: John -> Sherlock",
"TX3: John -> Mary",
"TX4: Mary -> Sherlock"
];
(b) (6 points) Implement verify function to verify transaction. If one put the values
transaction, index, root and proof into the verify function call, it will return true.
If there is even the slightest change in any data we get false.
function verify(string memory transaction, uint index, bytes32 root,
bytes32[] memory proof) public pure returns(bool) {
(c) (6 points) Implement makeHash which returns the hash value of an transaction.
function makeHash(string memory input) public pure returns(bytes32) {
Solution:
-
CSIT6000Q (L1) Final Exam Question Paper - Page 20 of 24 16/12/2023
# STATE VARIABLES:
owner: public(address)
x1: public(uint256)
x2: public(uint256)
bestSolution: public(uint256)
addressOfWinner: public(address)
durationInBlocks: public(uint256)
competitionEnd: public(uint256)
claimPeriodeLength: public(uint256)
# METHODS:
@public
def __init__(_durationInBlocks: uint256):
self.owner = msg.sender
self.bestSolution = 0
self.durationInBlocks = _durationInBlocks
self.competitionEnd = block.number + _durationInBlocks
self.addressOfWinner = ZERO_ADDRESS
# set claim periode to three days
# assuming an average blocktime of 14 seconds -> 86400/14
self.claimPeriodeLength = 6172
@public
@payable
def __default__():
# return any funds sent to the contract address directly
send(msg.sender, msg.value)
@private
def _calculateNewSolution(_x1: uint256, _x2: uint256) -> uint256:
# check new parameters against constraints
assert _x1 <= 40
assert _x2 <= 35
assert (3 * _x1) + (2 * _x2) <= 200
assert _x1 + _x2 <= 120
assert _x1 > 0 and _x2 > 0
# calculate and return new solution
return (4 * _x1) + (6 * _x2)
CSIT6000Q (L1) Final Exam Question Paper - Page 22 of 24 16/12/2023
@public
def submitSolution(_x1: uint256, _x2: uint256) -> uint256:
newSolution: uint256
newSolution = self._calculateNewSolution(_x1, _x2)
assert newSolution > self.bestSolution
# save the solution and its values
self.x1 = _x1
self.x2 = _x2
self.bestSolution = newSolution
self.addressOfWinner = msg.sender
log.NewSolutionFound(msg.sender, newSolution)
return newSolution
@public
def claimBounty():
assert block.number > self.competitionEnd
if (self.addressOfWinner == ZERO_ADDRESS):
# no solution was found -> extend duration of competition
self.competitionEnd = block.number + self.durationInBlocks
else:
assert block.number < (self.competitionEnd +
self.claimPeriodeLength)
assert msg.sender == self.addressOfWinner
send(self.addressOfWinner, self.balance)
# extend duration of competition
self.competitionEnd = block.number + self.durationInBlocks
log.BountyTransferred(self.addressOfWinner, self.balance)
@public
@payable
def topUpBounty():
log.BountyIncreased(msg.value)
@public
def extendCompetition():
# only if no valid solution has been submitted
assert self.addressOfWinner == ZERO_ADDRESS
assert block.number > (self.competitionEnd + self.claimPeriodeLength)
# extend duration of competition
self.competitionEnd = block.number + self.durationInBlocks
# reset winner address
self.addressOfWinner = ZERO_ADDRESS
CSIT6000Q (L1) Final Exam Question Paper - Page 23 of 24 16/12/2023
log.CompetitionTimeExtended(self.competitionEnd)
Solution:
-
-
CSIT6000Q (L1) Final Exam Question Paper - Page 24 of 24 16/12/2023