Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
cache/
out/
artifacts/
lib/
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typically we want to keep lib so ppl can just run forge install when playing with the repo


# Ignores development broadcast logs
!/broadcast
Expand All @@ -14,4 +15,4 @@ artifacts/
node_modules/
hh-cache

.DS_Store
.DS_Store
2 changes: 1 addition & 1 deletion lib/openzeppelin-contracts
2 changes: 1 addition & 1 deletion lib/solady
31 changes: 16 additions & 15 deletions src/Conclusion.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add this back

pragma solidity 0.8.13;

import "openzeppelin/token/ERC721/ERC721.sol";
import "openzeppelin/access/Ownable.sol";
Expand All @@ -12,8 +12,8 @@ contract Conclusion is ERC721, Ownable {
error MergeHasOccured();

struct MintInfo {
uint128 blockNum;
uint128 blockdifficulty;
uint128 blockNumber;
uint128 blockDifficulty;
}

uint256 public lastWorkBlock;
Expand All @@ -29,17 +29,17 @@ contract Conclusion is ERC721, Ownable {
_;
}

constructor() ERC721("Conclusion", "CONCLUSION") {}
constructor() ERC721("The Last Work", "CONCLUSION") {}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do 'sunset' and 'sunrise' for POS


function setRenderer(address renderer) external onlyOwner {
conclusionRenderer = renderer;
}

function mint() external onlyEOA {
if (mintedBlocks[tx.origin] > 0) revert AlreadyMinted();
if (mergeHasOccured()) revert MergeHasOccured();
_assetPoW();

checkProofOfWorkValidAndUpdate();
if (mintedBlocks[tx.origin] > 0)
revert AlreadyMinted();

uint256 currSupply = totalSupply;

Expand All @@ -56,13 +56,14 @@ contract Conclusion is ERC721, Ownable {
totalSupply = currSupply;
}

function checkProofOfWorkValidAndUpdate() public {
if (!mergeHasOccured()) {
lastWorkBlock = block.number;
}
function _assetPoW() internal {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asset or assess?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert

if (isPoS())
revert MergeHasOccured();

lastWorkBlock = block.number;
}

function mergeHasOccured() public view returns (bool) {
function isPoS() public view returns (bool) {
return block.difficulty > 2**64 || block.difficulty == 0;
}

Expand All @@ -73,11 +74,11 @@ contract Conclusion is ERC721, Ownable {
override
returns (string memory)
{
if (!_exists(_tokenId)) revert TokenDoesNotExist();
if (!_exists(_tokenId))
revert TokenDoesNotExist();

if (conclusionRenderer == address(0)) {
if (conclusionRenderer == address(0))
return "";
}

MintInfo memory info = tokenToBlockNum[_tokenId];

Expand Down
40 changes: 24 additions & 16 deletions src/Genesis.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ contract Genesis is ERC721, Ownable {
error AlreadyMinted();
error TokenDoesNotExist();
error MergeHasNotOccured();
error TooLate();

uint256 immutable MAX_MINT_DISTANCE = 100;

struct MintInfo {
uint128 blockNum;
uint128 blockdifficulty;
uint128 blockNumber;
uint128 blockDifficulty;
}

uint256 public genesisMergeBlock;
Expand All @@ -29,17 +32,20 @@ contract Genesis is ERC721, Ownable {
_;
}

constructor() ERC721("Genesis", "GENESIS") {}
constructor() ERC721("New Genesis", "GENESIS") {}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sunrise


function setRenderer(address renderer) external onlyOwner {
genesisRenderer = renderer;
}

function mint() external onlyEOA {
if (mintedBlocks[tx.origin] > 0) revert AlreadyMinted();
if (!mergeHasOccured()) revert MergeHasNotOccured();
function mint() external onlyEOA {
assertPos();

if (mintedBlocks[tx.origin] > 0)
revert AlreadyMinted();

checkForMergeAndUpdate();
if (block.number - genesisMergeBlock > MAX_MINT_DISTANCE)
revert TooLate();

uint256 currSupply = totalSupply;

Expand All @@ -56,13 +62,15 @@ contract Genesis is ERC721, Ownable {
totalSupply = currSupply;
}

function checkForMergeAndUpdate() public {
if (genesisMergeBlock == 0 && mergeHasOccured()) {
function assertPoS() public {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking we could make this a function anyone could call just so we can keep updating the blocks (so we can guarantee not missing the POS block)

if (!isPoS())
revert MergeHasNotOccured();

if (genesisMergeBlock == 0)
genesisMergeBlock = block.number;
}
}

function mergeHasOccured() public view returns (bool) {
function isPoS() public view returns (bool) {
return block.difficulty > 2**64 || block.difficulty == 0;
}

Expand All @@ -73,19 +81,19 @@ contract Genesis is ERC721, Ownable {
override
returns (string memory)
{
if (!_exists(_tokenId)) revert TokenDoesNotExist();
if (!_exists(_tokenId))
revert TokenDoesNotExist();

if (genesisRenderer == address(0)) {
if (genesisRenderer == address(0))
return "";
}

MintInfo memory info = tokenToBlockNum[_tokenId];

return
IGenesisRenderer(genesisRenderer).tokenURI(
_tokenId,
info.blockNum,
info.blockdifficulty
info.blockNumber,
genesisMergeBlock
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is suppose to be the block difficulty the minter minted at - for metadata purposes

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PoS doesn't have block.difficulty (it's prevrandao then) so I re-purposed it to show when genesisMergeBlock (since it isn't known while PoW, so it's a nice compromise)

);
}
}
31 changes: 22 additions & 9 deletions test/Conclusion.t.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
// // SPDX-License-Identifier: UNLICENSED
// pragma solidity ^0.8.13;
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

// import "forge-std/Test.sol";
// import "../src/Conclusion.sol";
import "forge-std/Test.sol";
import "../src/Conclusion.sol";

// contract ConclusionTest is Test {
// function setUp() public {
// }
contract ConclusionTest is Test {
Conclusion public c;
function setUp() public {
c = new Conclusion();
vm.difficulty(2**25);
}

// }
function test_mintContract() public {
vm.expectRevert("only EOA");
c.mint();
}

// didnt have time to write tests T_T , but it was reviewed by some big brains.
function test_mint() public {
vm.prank(0x4C9ACeE7Ba4d5AFD8408D0c68591e2ABB01A3ec9, 0x4C9ACeE7Ba4d5AFD8408D0c68591e2ABB01A3ec9);
c.mint();
}

function test_idk() public {
}
}
26 changes: 26 additions & 0 deletions test/Genesis.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.13;

import "forge-std/Test.sol";
import "../src/Genesis.sol";

contract GenesisTest is Test {
Genesis public g;
function setUp() public {
g = new Genesis();
vm.difficulty(2**255);
}

function mintContract() public {
vm.expectRevert("only EOA");
g.mint();
}

function test_mint() public {
vm.prank(0x4C9ACeE7Ba4d5AFD8408D0c68591e2ABB01A3ec9, 0x4C9ACeE7Ba4d5AFD8408D0c68591e2ABB01A3ec9);
g.mint();
}

function test_idk() public {
}
}