Skip to content

Instantly share code, notes, and snippets.

@alofeoluwafemi
Created June 25, 2022 21:59
Show Gist options
  • Save alofeoluwafemi/28a037c0f7e632b725deef11d75c053d to your computer and use it in GitHub Desktop.
Save alofeoluwafemi/28a037c0f7e632b725deef11d75c053d to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract KeylessHiddenEthCreator {
uint public currentContractNonce = 1; // keep track of this contracts nonce publicly (it's also found in the contracts state)
// determine future addresses which can hide ether.
function futureAddresses(uint8 nonce) public view returns (address) {
if(nonce == 0) {
return address(uint160(uint256(keccak256(abi.encodePacked(bytes32("0xd6"), bytes32("0x94"), this, bytes32("0x80"))))));
}
return address(uint160(uint256(keccak256(abi.encodePacked(bytes32("0xd6"), bytes32("0x94"), this, nonce)))));
// need to implement rlp encoding properly for a full range of nonces
}
// increment the contract nonce or retrieve ether from a hidden/key-less account
// provided the nonce is correct
function retrieveHiddenEther(address beneficiary) public returns (address) {
currentContractNonce +=1;
return address(new RecoverContract(beneficiary));
}
fallback () external {} // Allow ether transfers (helps for playing in remix)
}
contract RecoverContract {
constructor(address beneficiary) {
selfdestruct(payable(beneficiary)); // don't deploy code. Return the ether stored here to the beneficiary.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment