Skip to content

Commit

Permalink
improve initial setting of secret ContractPubkey - Owner can set unti…
Browse files Browse the repository at this point in the history
…l it is changed to anything >=2**160
  • Loading branch information
xxxxxx committed Oct 6, 2024
1 parent 0b63779 commit 6bfecba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/hardhat/contracts/payWithEth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ contract NunyaBusiness {
constructor(address payable _gateway) payable {
gateway = _gateway;
secretContract = SecretContract(_gateway);
// Lock secretContractPubkey to requestId so that only that request cn set it.
// TODO: make it better - if call fails, contract is stuck and needs redploy :P
fundGateway(msg.value);
secretContractPubkey = secretContract.retrievePubkey();

secretContract.retrievePubkey();
// Lock secretContractPubkey to Owner. After it is set it cannot be reset.
secretContractPubkey = uint256(uint160(msg.sender));
}

modifier onlyGateway {
Expand All @@ -57,8 +58,9 @@ contract NunyaBusiness {

function setSecretContractPubkeyCallback (uint256 _requestId, uint256 _key) public onlyGateway {
// require (secretContractPubkey==0, "Key already set");
require (secretContractPubkey==_requestId, "Only the contract constructor can trigger this function");
// TODO: Make sure it's our secret contract setting the key, not some interloper
// Make sure it's our secret contract setting the key, not some interloper
// (will fail one time in 2^96 ;)
require (secretContractPubkey < 2**160, "Only the contract constructor can trigger this function");
secretContractPubkey=_key;
}

Expand Down

0 comments on commit 6bfecba

Please sign in to comment.