-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathverifynameregistry.sol
67 lines (54 loc) · 1.6 KB
/
verifynameregistry.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
pragma solidity ^0.4.25;
// Name Registrar
contract NameRegistry {
address public owner;
bool public lock;
struct NameRecord {
// map hashes to addresses
bytes32 name; //
address mappedAddress;
}
mapping(address => NameRecord) public registeredNameRecord; // records who registered names
mapping(bytes32 => address) public resolve; // resolves hashes to addresses
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
constructor() public {
owner = msg.sender;
}
function register(bytes32 _name, address _mappedAddress) public {
// set up the new NameRecord
NameRecord newRecord;
newRecord.name = _name;
newRecord.mappedAddress = _mappedAddress;
resolve[_name] = _mappedAddress;
registeredNameRecord[msg.sender] = newRecord;
}
function lock() public onlyOwner {
lock = true;
}
}
contract VerifyNameRegistry is NameRegistry {
event AssertionFailed(string message);
address public original_owner;
constructor() {
original_owner = owner;
}
modifier checkInvariants() {
bool lock_old = lock;
_;
if (msg.sender != original_owner && lock != lock_old) {
emit AssertionFailed(
"[CONTRACT INVARIANT] Lock state variable was modified but sender is not the contract owner"
);
assert(false);
}
}
function register(bytes32 _name, address _mappedAddress)
public
checkInvariants
{
super.register(_name, _mappedAddress);
}
}