Skip to content

Instantly share code, notes, and snippets.

@bl4ck5un
Created February 25, 2019 21:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bl4ck5un/f4e593043fd06f7bbaf8b9ec42cbff10 to your computer and use it in GitHub Desktop.
Save bl4ck5un/f4e593043fd06f7bbaf8b9ec42cbff10 to your computer and use it in GitHub Desktop.
Difference between the old and the new cryptokitties' geneScience smart contract
diff --git a/old.sol b/new.sol
index 0184107..1419bcd 100644
--- a/old.sol
+++ b/new.sol
@@ -1,16 +1,35 @@
pragma solidity ^0.4.18;
-
+contract KittyCoreInterface {
+ function cooAddress() public returns(address);
+}
/// @title GeneScience implements the trait calculation for new kitties
-/// @author Axiom Zen, Dieter Shirley <dete@axiomzen.co> (https://github.com/dete), Fabiano P. Soriani <fabianosoriani@gmail.com> (https://github.com/flockonus), Jordan Schalm <jordan.schalm@gmail.com> (https://github.com/jordanschalm)
+/// @author Axiom Zen, Dieter Shirley <dete@axiomzen.co> (https://github.com/dete), Fabiano P. Soriani <fabianosoriani@gmail.com> (https://github.com/flockonus), Jordan Schalm <jordan.schalm@gmail.com> (https://github.com/jordanschalm), Abhishek Chadha <abhishek@dapperlabs.com> (https://github.com/achadha235)
contract GeneScience {
bool public isGeneScience = true;
uint256 internal constant maskLast8Bits = uint256(0xff);
uint256 internal constant maskFirst248Bits = uint256(~0xff);
- function GeneScience() public {}
+ // This is the privileged birther address. If this is set to 0, privileged birthing is disabled
+ address internal _privilegedBirther;
+ // Privileged window size for birthers, set to 5 blocks.
+ uint256 public privilegedBirtherWindowSize = 5;
+ KittyCoreInterface _kittyCore;
+
+ function GeneScience(address _privilegedBirtherAddress, address _kittyCoreAddress) public {
+ require(_kittyCoreAddress != address(0));
+ _kittyCore = KittyCoreInterface(_kittyCoreAddress);
+ _privilegedBirther = _privilegedBirtherAddress;
+ }
+
+ /// @dev set the privileged birther address
+ /// @param _birtherAddress the new birther address
+ function setPrivilegedBirther(address _birtherAddress) public {
+ require(msg.sender == _kittyCore.cooAddress());
+ _privilegedBirther = _birtherAddress;
+ }
/// @dev given a characteristic and 2 genes (unsorted) - returns > 0 if the genes ascended, that's the value
/// @param trait1 any trait of that characteristic
@@ -99,7 +118,14 @@ contract GeneScience {
/// @dev the function as defined in the breeding contract - as defined in CK bible
function mixGenes(uint256 _genes1, uint256 _genes2, uint256 _targetBlock) public returns (uint256) {
- require(block.number > _targetBlock);
+ if (_privilegedBirther == address(0) || tx.origin == _privilegedBirther) {
+ // Allow immediate births if there is no privileged birther, or if the originator
+ // of the transaction is the privileged birther
+ require(block.number > _targetBlock);
+ } else {
+ require(block.number > _targetBlock + privilegedBirtherWindowSize);
+ }
+
// Try to grab the hash of the "target block". This should be available the vast
// majority of the time (it will only fail if no-one calls giveBirth() within 256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment