Have the Router track its deployment block

Prevents a consensus split where some nodes would drop transfers if their node
didn't think the Router was deployed, and some would handle them.
This commit is contained in:
Luke Parker
2024-09-20 01:24:28 -04:00
parent 294462641e
commit 7e4c59a0a3
3 changed files with 38 additions and 4 deletions

View File

@@ -7,6 +7,9 @@ import "Schnorr.sol";
// _ is used as a prefix for internal functions and smart-contract-scoped variables
contract Router {
// The block at which this contract was deployed.
uint256 private _deploymentBlock;
// Nonce is incremented for each command executed, preventing replays
uint256 private _nonce;
@@ -63,6 +66,8 @@ contract Router {
}
constructor(bytes32 initialSeraiKey) _updateSeraiKeyAtEndOfFn(0, initialSeraiKey) {
_deploymentBlock = block.number;
// We consumed nonce 0 when setting the initial Serai key
_nonce = 1;
// Nonces are incremented by 1 upon account creation, prior to any code execution, per EIP-161
@@ -230,6 +235,10 @@ contract Router {
return _nonce;
}
function deploymentBlock() external view returns (uint256) {
return _deploymentBlock;
}
function smartContractNonce() external view returns (uint256) {
return _smartContractNonce;
}