-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(@agora): AG-25 configured evm compiler configured the evm compiler in the hardhat configuration file * refactor(@contracts): AG-25 refactored DECs Registry contract refactored DECs registry contract * refactor(@contracts): AG-25 refactored DEC contract refactored DEC smart contract * feat(@contracts): AG-25 added name property to DECs Registry added name property to DECs Registry smart contract * feat(@contracts): ignition modules implementation implemented the ignition modules for contracts deploy * fix(@contracts): AG-25 added folder to gitignore added foldet to gitignore * fix(@contracts): AG-25 ignored files added files to gitignore
- Loading branch information
Showing
17 changed files
with
258 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,7 @@ node_modules | |
/coverage.json | ||
|
||
# reports folder | ||
report | ||
report | ||
|
||
#ignition files | ||
/ignition/deployments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
pragma solidity ^0.8.24; | ||
|
||
/// @title The Voter's Digital Electoral Cards | ||
/// @title The Voter's Digital Electoral Card | ||
/// @author Christian Palazzo <[email protected]> | ||
/// @custom:experimental This is an experimental contract. | ||
contract DEC { | ||
address public owner; | ||
bytes taxCode; | ||
bytes municipality; | ||
bytes region; | ||
bytes country; | ||
|
||
constructor() { | ||
constructor( | ||
bytes memory _taxCode, | ||
bytes memory _municipality, | ||
bytes memory _region, | ||
bytes memory _country | ||
) { | ||
/// @dev only the owner of the contract has write permissions | ||
owner = msg.sender; | ||
taxCode = _taxCode; | ||
municipality = _municipality; | ||
region = _region; | ||
country = _country; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Only owner can call this function"); | ||
_; | ||
} | ||
|
||
/// @notice This is the Digital Electoral Card, emitted by a public third-party authority and owned by the Voter | ||
/// @dev This data is encrypted with the Voter's public address and only the Voter can decrypt it using the private key | ||
struct decData { | ||
string taxCode; | ||
string municipality; | ||
string province; | ||
string region; | ||
string country; | ||
function setTaxCode(bytes memory _taxCode) public onlyOwner { | ||
taxCode = _taxCode; | ||
} | ||
|
||
event DECEncrypted(address indexed owner, bytes encryptedData); | ||
function getTaxCode() public view returns (bytes memory) { | ||
return taxCode; | ||
} | ||
|
||
/// @notice This function is used to encrypt ad digitally sign a DEC | ||
function encryptDEC( | ||
decData memory dec | ||
) public onlyOwner returns (bytes memory) { | ||
bytes memory encodedData = abi.encodePacked( | ||
dec.taxCode, | ||
dec.municipality, | ||
dec.province, | ||
dec.region, | ||
dec.country | ||
); | ||
bytes32 hashedData = keccak256(encodedData); | ||
bytes memory signature = signData(hashedData); | ||
function setMunicipality(bytes memory _municipality) public onlyOwner { | ||
municipality = _municipality; | ||
} | ||
|
||
emit DECEncrypted(msg.sender, abi.encodePacked(hashedData, signature)); | ||
function getMunicipality() public view returns (bytes memory) { | ||
return municipality; | ||
} | ||
|
||
return abi.encodePacked(hashedData, signature); | ||
function setRegion(bytes memory _region) public onlyOwner { | ||
region = _region; | ||
} | ||
|
||
/// @notice This function is used to digitally sign the data | ||
function signData(bytes32 data) private pure returns (bytes memory) { | ||
bytes32 hash = keccak256( | ||
abi.encodePacked("\x19Ethereum Signed Message:\n32", data) | ||
); | ||
bytes1 v = bytes1(0); | ||
bytes32 r = bytes32(0); | ||
bytes32 s = uintToBytes32(1); | ||
return abi.encodePacked(ecrecover(hash, uint8(v), r, s), r, s); | ||
function getRegion() public view returns (bytes memory) { | ||
return region; | ||
} | ||
|
||
/// @notice this function is used in signData function | ||
function uintToBytes32(uint256 x) private pure returns (bytes32) { | ||
return bytes32(x); | ||
function setCountry(bytes memory _country) public onlyOwner { | ||
country = _country; | ||
} | ||
|
||
function getCountry() public view returns (bytes memory) { | ||
return country; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,36 +6,57 @@ import "./DEC.sol"; | |
/// @title The Registry of the Digital Electoral Cards | ||
/// @author Christian Palazzo <[email protected]> | ||
/// @custom:experimental This is an experimental contract. | ||
contract DECsRegistry is DEC { | ||
constructor() DEC() {} | ||
contract DECsRegistry { | ||
address public owner; | ||
string public name; | ||
|
||
/// @notice this is the list of stamps of elections in which the voter participated | ||
/// @dev the first address is related to the Voter's EOA, the second array is the Voter's stamps list | ||
/// @dev the first address is related to the Voter's DEC, the second array is the Voter's stamps list | ||
mapping(address => address[]) electoralStamps; | ||
|
||
/// @notice this function contains the list of DECs | ||
/// @dev the address is related to the Voter's EOA | ||
mapping(address => bytes) registry; | ||
/// @dev the first address is related to the Voter's EOA, the second address is related to the DEC | ||
mapping(address => address) registry; | ||
|
||
event DECRegistered(address indexed voter, bytes dec); | ||
event DECRegistered(address indexed voter, address dec); | ||
event DECStamped(address indexed election, address indexed voter); | ||
|
||
constructor(string memory _name) { | ||
/// @dev only the owner of the contract has write permissions | ||
owner = msg.sender; | ||
name = _name; | ||
} | ||
|
||
modifier onlyOwner() { | ||
require(msg.sender == owner, "Only owner can call this function"); | ||
_; | ||
} | ||
|
||
/// @notice DECs REgistry name setter function | ||
function setName(string memory _name) public onlyOwner { | ||
name = _name; | ||
} | ||
|
||
/// @notice DECs REgistry name getter function | ||
function getName() public view returns (string memory) { | ||
return name; | ||
} | ||
|
||
/// @notice this function is used by the third party authority to register a Voter's DEC in the registry | ||
/// @dev the DEC contains sensitive data that must be encrypted | ||
function registerDEC(decData memory dec, address voter) public onlyOwner { | ||
function registerDEC(address dec, address voter) public onlyOwner { | ||
require( | ||
registry[voter].length == 0, | ||
registry[voter] == address(0), | ||
"The Voter's DEC has been already registered" | ||
); | ||
registry[voter] = encryptDEC(dec); | ||
registry[voter] = dec; | ||
emit DECRegistered(voter, registry[voter]); | ||
return; | ||
} | ||
|
||
/// @notice this function returns an encrypted DEC in order to check if a Voter has the voting rights | ||
function getDEC(address voter) public view returns (bytes memory) { | ||
function getDEC(address voter) public view returns (address) { | ||
require( | ||
registry[voter].length != 0, | ||
registry[voter] != address(0), | ||
"The Voter don't have a registered DEC" | ||
); | ||
return registry[voter]; | ||
|
@@ -54,9 +75,8 @@ contract DECsRegistry is DEC { | |
return false; | ||
} | ||
|
||
/// @notice this function put the election stamp on the Voter's DEC after the vote | ||
/// @dev the owner of the DECs registry is the same of the election smart contract (third party authority) | ||
function stampsTheDEC(address election, address voter) public onlyOwner { | ||
/// @notice this function put the election stamp on the Voter's stamps list after the vote | ||
function stamps(address election, address voter) public onlyOwner { | ||
electoralStamps[voter].push(election); | ||
emit DECStamped(election, voter); | ||
return; | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; | ||
|
||
export default buildModule("DEC", (m) => { | ||
const DEC1 = m.contract("TomsDEC", [ | ||
"RSSMRA85C27H501W", | ||
"Ardea", | ||
"Lazio", | ||
"Italy", | ||
]); | ||
|
||
m.call(DEC1, "getName", []); | ||
|
||
return { DEC1 }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules"; | ||
|
||
export default buildModule("DECsRegistry", (m) => { | ||
const italianRegistry = m.contract("DECsRegistry", ["Italy"]); | ||
|
||
m.call(italianRegistry, "getName", []); | ||
|
||
return { italianRegistry }; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
if [ "$#" -ne 2 ]; then | ||
echo "Usage: $0 <module_path> <network>" | ||
exit 1 | ||
fi | ||
|
||
MODULE_PATH="$1" | ||
NETWORK="$2" | ||
|
||
npx hardhat ignition deploy "$MODULE_PATH" --network "$NETWORK" |
Oops, something went wrong.