generated from zama-ai/fhevm-hardhat-template
-
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.
added random in constructor and same pattern with a clone factory + w…
…orking tests
- Loading branch information
Showing
12 changed files
with
167 additions
and
323 deletions.
There are no files selected for viewing
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "fhevm/lib/TFHE.sol"; | ||
|
||
contract RandomInConstructor { | ||
euint32 private random; | ||
|
||
constructor() { | ||
random = TFHE.rem(TFHE.randEuint32(),100); | ||
} | ||
|
||
// Returns the name of the token. | ||
function result() public view virtual returns (uint32) { | ||
return TFHE.decrypt(random); | ||
} | ||
|
||
} |
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,23 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "@openzeppelin/contracts/proxy/Clones.sol"; | ||
import { RandomInConstructorInitializable } from "./RandomInConstructorInitializable.sol"; | ||
|
||
contract RandomInConstructorFactory{ | ||
address private immutable implementation; | ||
|
||
constructor(address _implementation) { | ||
implementation = _implementation; | ||
} | ||
|
||
function clone(bytes32 salt) public returns (address cloneAdd){ | ||
cloneAdd = Clones.cloneDeterministic(implementation,salt); | ||
RandomInConstructorInitializable(cloneAdd).initialize(); | ||
} | ||
|
||
function predictAddress(bytes32 salt) public view returns (address predicted){ | ||
predicted = Clones.predictDeterministicAddress(implementation,salt); | ||
} | ||
} |
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,24 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import "fhevm/lib/TFHE.sol"; | ||
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; | ||
|
||
contract RandomInConstructorInitializable is Initializable{ | ||
euint32 private random; | ||
|
||
constructor() { | ||
_disableInitializers(); | ||
} | ||
|
||
function initialize() external initializer{ | ||
random = TFHE.randEuint32(); | ||
} | ||
|
||
// Returns the name of the token. | ||
function result() public view virtual returns (uint32) { | ||
return TFHE.decrypt(random); | ||
} | ||
|
||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.