Skip to content

Commit

Permalink
Merge pull request #1774 from opentensor/hotfix/6.10.1
Browse files Browse the repository at this point in the history
Revert nonce implementation fix
  • Loading branch information
ifrit98 committed Apr 5, 2024
2 parents c5dabe0 + 5bf1b3f commit bfc7877
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 6.10.1 / 2024-04-05
## What's Changed
* Revert nonce implementation fix #1774: Breaking change needs to telegraphed in next release.

## 6.10.0 / 2024-03-25

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.10.0
6.10.1
2 changes: 1 addition & 1 deletion bittensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
nest_asyncio.apply()

# Bittensor code and protocol version.
__version__ = "6.10.0"
__version__ = "6.10.1"

version_split = __version__.split(".")
__version_as_int__: int = (
Expand Down
23 changes: 6 additions & 17 deletions bittensor/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,25 +914,14 @@ async def default_verify(self, synapse: bittensor.Synapse):
# Build the unique endpoint key.
endpoint_key = f"{synapse.dendrite.hotkey}:{synapse.dendrite.uuid}"

# Check the nonce from the endpoint key with 4 second delta
allowedDelta = 4000000000

# Requests must have nonces to be safe from replays
if synapse.dendrite.nonce is None:
raise Exception("Missing Nonce")

# If we don't have a nonce stored, ensure that the nonce falls within
# a reasonable delta.
if (
self.nonces.get(endpoint_key) is None
and synapse.dendrite.nonce <= time.time_ns() - allowedDelta
):
raise Exception("Nonce is too old")
# Check the nonce from the endpoint key.
if (
self.nonces.get(endpoint_key) is not None
endpoint_key in self.nonces.keys()
and self.nonces[endpoint_key] is not None
and synapse.dendrite.nonce is not None
and synapse.dendrite.nonce <= self.nonces[endpoint_key]
):
raise Exception("Nonce is too old")
raise Exception("Nonce is too small")

if not keypair.verify(message, synapse.dendrite.signature):
raise Exception(
Expand Down Expand Up @@ -1201,7 +1190,7 @@ async def preprocess(self, request: Request) -> bittensor.Synapse:
{
"version": str(bittensor.__version_as_int__),
"uuid": str(self.axon.uuid),
"nonce": f"{time.time_ns()}",
"nonce": f"{time.monotonic_ns()}",
"status_message": "Success",
"status_code": "100",
}
Expand Down
2 changes: 1 addition & 1 deletion bittensor/dendrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def preprocess_synapse_for_request(
synapse.dendrite = bittensor.TerminalInfo(
ip=self.external_ip,
version=bittensor.__version_as_int__,
nonce=time.time_ns(),
nonce=time.monotonic_ns(),
uuid=self.uuid,
hotkey=self.keypair.ss58_address,
)
Expand Down
6 changes: 3 additions & 3 deletions bittensor/synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class TerminalInfo(pydantic.BaseModel):
ip (str): IP address of the terminal, crucial for network routing and data transmission.
port (int): Network port used by the terminal, key for establishing network connections.
version (int): Bittensor version running on the terminal, ensuring compatibility between different nodes in the network.
nonce (int): Unix timestamp that linearly increases for each request, ensuring requests cannot be duplicated or repeated
nonce (int): Unique, monotonically increasing number for each terminal, aiding in identifying and ordering network interactions.
uuid (str): Unique identifier for the terminal, fundamental for network security and identification.
hotkey (str): Encoded hotkey string of the terminal wallet, important for transaction and identity verification in the network.
signature (str): Digital signature verifying the tuple of nonce, axon_hotkey, dendrite_hotkey, and uuid, critical for ensuring data authenticity and security.
Expand Down Expand Up @@ -211,10 +211,10 @@ class Config:
cast_int
)

# A Unix timestamp to associate with the terminal
# A unique monotonically increasing integer nonce associate with the terminal
nonce: Optional[int] = pydantic.Field(
title="nonce",
description="A Unix timestamp that prevents replay attacks",
description="A unique monotonically increasing integer nonce associate with the terminal generated from time.monotonic_ns()",
examples=111111,
default=None,
allow_mutation=True,
Expand Down

0 comments on commit bfc7877

Please sign in to comment.