-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3922eaa
commit 656eabc
Showing
8 changed files
with
1,891 additions
and
636 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,82 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0 <0.9.0; | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
// Useful for debugging. Remove when deploying to a live network. | ||
import "./Poseidon.sol"; | ||
import "hardhat/console.sol"; | ||
import "./Groth16Verifier.sol"; | ||
|
||
// Use openzeppelin to inherit battle-tested implementations (ERC20, ERC721, etc) | ||
// import "@openzeppelin/contracts/access/Ownable.sol"; | ||
contract YourContract is Groth16Verifier, Poseidon { | ||
// The known hash of the FrogCrypto signer | ||
uint256 constant FROGCRYPTO_SIGNER_HASH = | ||
320469162396708332516033932244029190181315114284264408621970394677041964715; | ||
|
||
/** | ||
* A smart contract that allows changing a state variable of the contract and tracking the changes | ||
* It also allows the owner to withdraw the Ether in the contract | ||
* @author BuidlGuidl | ||
*/ | ||
contract YourContract { | ||
// State Variables | ||
address public immutable owner; | ||
string public greeting = "Building Unstoppable Apps!!!"; | ||
bool public premium = false; | ||
uint256 public totalCounter = 0; | ||
mapping(address => uint) public userGreetingCounter; | ||
|
||
// Events: a way to emit log statements from smart contract that can be listened to by external parties | ||
event GreetingChange( | ||
address indexed greetingSetter, | ||
string newGreeting, | ||
bool premium, | ||
uint256 value | ||
); | ||
|
||
// Constructor: Called once on contract deployment | ||
// Check packages/hardhat/deploy/00_deploy_your_contract.ts | ||
constructor(address _owner) { | ||
owner = _owner; | ||
struct ProofArgs { | ||
uint256[2] _pA; | ||
uint256[2][2] _pB; | ||
uint256[2] _pC; | ||
uint256[56] _pubSignals; | ||
} | ||
|
||
// Modifier: used to define a set of rules that must be met before or after a function is executed | ||
// Check the withdraw() function | ||
modifier isOwner() { | ||
// msg.sender: predefined variable that represents address of the account that called the current function | ||
require(msg.sender == owner, "Not the Owner"); | ||
modifier verifiedProof(ProofArgs calldata proof) { | ||
require( | ||
this.verifyProof( | ||
proof._pA, | ||
proof._pB, | ||
proof._pC, | ||
proof._pubSignals | ||
), | ||
"Invalid proof" | ||
); | ||
_; | ||
} | ||
|
||
/** | ||
* Function that allows anyone to change the state variable "greeting" of the contract and increase the counters | ||
* | ||
* @param _newGreeting (string memory) - new greeting to save on the contract | ||
*/ | ||
function setGreeting(string memory _newGreeting) public payable { | ||
// Print data to the hardhat chain console. Remove when deploying to a live network. | ||
console.log( | ||
"Setting new greeting '%s' from %s", | ||
_newGreeting, | ||
msg.sender | ||
function verifyAndExtractFrog( | ||
ProofArgs calldata proof, | ||
// User provided values to verify | ||
uint256 beauty, | ||
uint256 biome, | ||
uint256 intelligence, | ||
uint256 jump, | ||
uint256 speed, | ||
uint256 rarity, | ||
uint256 owner | ||
) public view returns (bool) { | ||
uint256[56] memory pubSignals = proof._pubSignals; | ||
// Verify FrogCrypto signer | ||
require(pubSignals[23] == FROGCRYPTO_SIGNER_HASH, "Invalid signer"); | ||
|
||
uint256[1] memory input; | ||
// Verify beauty | ||
input[0] = beauty; | ||
require(this.hash(input) == pubSignals[0], "Invalid beauty value"); | ||
|
||
// Verify biome | ||
input[0] = biome; | ||
require(this.hash(input) == pubSignals[1], "Invalid biome value"); | ||
|
||
// Verify intelligence | ||
input[0] = intelligence; | ||
require( | ||
this.hash(input) == pubSignals[2], | ||
"Invalid intelligence value" | ||
); | ||
|
||
// Change state variables | ||
greeting = _newGreeting; | ||
totalCounter += 1; | ||
userGreetingCounter[msg.sender] += 1; | ||
// Verify jump | ||
input[0] = jump; | ||
require(this.hash(input) == pubSignals[3], "Invalid jump value"); | ||
|
||
// msg.value: built-in global variable that represents the amount of ether sent with the transaction | ||
if (msg.value > 0) { | ||
premium = true; | ||
} else { | ||
premium = false; | ||
} | ||
// Verify owner | ||
input[0] = owner; | ||
require(this.hash(input) == pubSignals[5], "Invalid owner value"); | ||
|
||
// emit: keyword used to trigger an event | ||
emit GreetingChange(msg.sender, _newGreeting, msg.value > 0, msg.value); | ||
} | ||
// Verify rarity | ||
input[0] = rarity; | ||
require(this.hash(input) == pubSignals[6], "Invalid rarity value"); | ||
|
||
/** | ||
* Function that allows the owner to withdraw all the Ether in the contract | ||
* The function can only be called by the owner of the contract as defined by the isOwner modifier | ||
*/ | ||
function withdraw() public isOwner { | ||
(bool success, ) = owner.call{ value: address(this).balance }(""); | ||
require(success, "Failed to send Ether"); | ||
} | ||
// Verify speed | ||
input[0] = speed; | ||
require(this.hash(input) == pubSignals[7], "Invalid speed value"); | ||
|
||
/** | ||
* Function that allows the contract to receive ETH | ||
*/ | ||
receive() external payable {} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.