Verified contractPartialBUSL-1.1
ChronicleVAO_Groma_GRO_Router_1
Address0x50bf8b207e64bbf0a523da83b4672cee518c03a7
- Balance
0 ETH
- Transactions
8
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 10,000 runs
- EVM version
- paris
- Via IR
- yes
- License
- BUSL-1.1
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,349,934
- Creation transaction
- 0xe27d3ba76e…ce22ae1aca
12 files
- script/instances/Groma_GRO/Router.solmain270 B
- dependencies/chronicle-std-2.1.0/src/auth/Auth.sol4.66 KB
- dependencies/chronicle-std-2.1.0/src/auth/IAuth.sol1.75 KB
- dependencies/chronicle-std-2.1.0/src/toll/IToll.sol1.73 KB
- dependencies/chronicle-std-2.1.0/src/toll/Toll.sol4.47 KB
- dependencies/uscribe-1.3.0/src/IUScribe.sol9.48 KB
- dependencies/uscribe-1.3.0/src/IUScribeRouter.sol841 B
- dependencies/uscribe-1.3.0/src/Types.sol279 B
- dependencies/uscribe-1.3.0/src/UScribeRouter.sol971 B
- dependencies/uscribe-1.3.0/src/libs/LibSecp256k1.sol13.8 KB
- src/IReader.sol1.21 KB
- src/Router.sol1.36 KB
script/instances/Groma_GRO/Router.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;
import {ChronicleVAO_Router} from "../../../src/Router.sol";
contract ChronicleVAO_Groma_GRO_Router_1 is ChronicleVAO_Router {
constructor(address initialAuthed) ChronicleVAO_Router(initialAuthed) {}
}
dependencies/chronicle-std-2.1.0/src/auth/Auth.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IAuth} from "./IAuth.sol";
/**
* @title Auth Module
*
* @dev The `Auth` contract module provides a basic access control mechanism,
* where a set of addresses are granted access to protected functions.
* These addresses are said to be _auth'ed_.
*
* Initially, the address given as constructor argument is the only address
* auth'ed. Through the `rely(address)` and `deny(address)` functions,
* auth'ed callers are able to grant/renounce auth to/from addresses.
*
* This module is used through inheritance. It will make available the
* modifier `auth`, which can be applied to functions to restrict their
* use to only auth'ed callers.
*/
abstract contract Auth is IAuth {
/// @dev Mapping storing whether address is auth'ed.
/// @custom:invariant Image of mapping is {0, 1}.
/// ∀x ∊ Address: _wards[x] ∊ {0, 1}
/// @custom:invariant Only address given as constructor argument is authenticated after deployment.
/// deploy(initialAuthed) → (∀x ∊ Address: _wards[x] == 1 → x == initialAuthed)
/// @custom:invariant Only functions `rely` and `deny` may mutate the mapping's state.
/// ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x])
/// → (msg.sig == "rely" ∨ msg.sig == "deny")
/// @custom:invariant Mapping's state may only be mutated by authenticated caller.
/// ∀x ∊ Address: preTx(_wards[x]) != postTx(_wards[x]) → _wards[msg.sender] = 1
mapping(address => uint) private _wards;
/// @dev List of addresses possibly being auth'ed.
/// @dev May contain duplicates.
/// @dev May contain addresses not being auth'ed anymore.
/// @custom:invariant Every address being auth'ed once is element of the list.
/// ∀x ∊ Address: authed(x) -> x ∊ _wardsTouched
address[] private _wardsTouched;
/// @dev Ensures caller is auth'ed.
modifier auth() {
assembly ("memory-safe") {
// Compute slot of _wards[msg.sender].
mstore(0x00, caller())
mstore(0x20, _wards.slot)
let slot := keccak256(0x00, 0x40)
// Revert if caller not auth'ed.
let isAuthed := sload(slot)
if iszero(isAuthed) {
// Store selector of `NotAuthorized(address)`.
mstore(0x00, 0x4a0bfec1)
// Store msg.sender.
mstore(0x20, caller())
// Revert with (offset, size).
revert(0x1c, 0x24)
}
}
_;
}
constructor(address initialAuthed) {
_wards[initialAuthed] = 1;
_wardsTouched.push(initialAuthed);
// Note to use address(0) as caller to indicate address was auth'ed
// during deployment.
emit AuthGranted(address(0), initialAuthed);
}
/// @inheritdoc IAuth
function rely(address who) external auth {
if (_wards[who] == 1) return;
_wards[who] = 1;
_wardsTouched.push(who);
emit AuthGranted(msg.sender, who);
}
/// @inheritdoc IAuth
function deny(address who) external auth {
if (_wards[who] == 0) return;
_wards[who] = 0;
emit AuthRenounced(msg.sender, who);
}
/// @inheritdoc IAuth
function authed(address who) public view returns (bool) {
return _wards[who] == 1;
}
/// @inheritdoc IAuth
/// @custom:invariant Only contains auth'ed addresses.
/// ∀x ∊ authed(): _wards[x] == 1
/// @custom:invariant Contains all auth'ed addresses.
/// ∀x ∊ Address: _wards[x] == 1 → x ∊ authed()
function authed() public view returns (address[] memory) {
// Initiate array with upper limit length.
address[] memory wardsList = new address[](_wardsTouched.length);
// Iterate through all possible auth'ed addresses.
uint ctr;
for (uint i; i < wardsList.length; i++) {
// Add address only if still auth'ed.
if (_wards[_wardsTouched[i]] == 1) {
wardsList[ctr++] = _wardsTouched[i];
}
}
// Set length of array to number of auth'ed addresses actually included.
assembly ("memory-safe") {
mstore(wardsList, ctr)
}
return wardsList;
}
/// @inheritdoc IAuth
function wards(address who) public view returns (uint) {
return _wards[who];
}
}
dependencies/chronicle-std-2.1.0/src/auth/IAuth.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
interface IAuth {
/// @notice Thrown by protected function if caller not auth'ed.
/// @param caller The caller's address.
error NotAuthorized(address caller);
/// @notice Emitted when auth granted to address.
/// @param caller The caller's address.
/// @param who The address auth got granted to.
event AuthGranted(address indexed caller, address indexed who);
/// @notice Emitted when auth renounced from address.
/// @param caller The caller's address.
/// @param who The address auth got renounced from.
event AuthRenounced(address indexed caller, address indexed who);
/// @notice Grants address `who` auth.
/// @dev Only callable by auth'ed address.
/// @param who The address to grant auth.
function rely(address who) external;
/// @notice Renounces address `who`'s auth.
/// @dev Only callable by auth'ed address.
/// @param who The address to renounce auth.
function deny(address who) external;
/// @notice Returns whether address `who` is auth'ed.
/// @param who The address to check.
/// @return True if `who` is auth'ed, false otherwise.
function authed(address who) external view returns (bool);
/// @notice Returns full list of addresses granted auth.
/// @dev May contain duplicates.
/// @return List of addresses granted auth.
function authed() external view returns (address[] memory);
/// @notice Returns whether address `who` is auth'ed.
/// @custom:deprecated Use `authed(address)(bool)` instead.
/// @param who The address to check.
/// @return 1 if `who` is auth'ed, 0 otherwise.
function wards(address who) external view returns (uint);
}
dependencies/chronicle-std-2.1.0/src/toll/IToll.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
interface IToll {
/// @notice Thrown by protected function if caller not tolled.
/// @param caller The caller's address.
error NotTolled(address caller);
/// @notice Emitted when toll granted to address.
/// @param caller The caller's address.
/// @param who The address toll got granted to.
event TollGranted(address indexed caller, address indexed who);
/// @notice Emitted when toll renounced from address.
/// @param caller The caller's address.
/// @param who The address toll got renounced from.
event TollRenounced(address indexed caller, address indexed who);
/// @notice Grants address `who` toll.
/// @dev Only callable by auth'ed address.
/// @param who The address to grant toll.
function kiss(address who) external;
/// @notice Renounces address `who`'s toll.
/// @dev Only callable by auth'ed address.
/// @param who The address to renounce toll.
function diss(address who) external;
/// @notice Returns whether address `who` is tolled.
/// @param who The address to check.
/// @return True if `who` is tolled, false otherwise.
function tolled(address who) external view returns (bool);
/// @notice Returns full list of addresses tolled.
/// @dev May contain duplicates.
/// @return List of addresses tolled.
function tolled() external view returns (address[] memory);
/// @notice Returns whether address `who` is tolled.
/// @custom:deprecated Use `tolled(address)(bool)` instead.
/// @param who The address to check.
/// @return 1 if `who` is tolled, 0 otherwise.
function bud(address who) external view returns (uint);
}
dependencies/chronicle-std-2.1.0/src/toll/Toll.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
import {IToll} from "./IToll.sol";
/**
* @title Toll Module
*
* @notice "Toll paid, we kiss - but dissension looms, maybe diss?"
*
* @dev The `Toll` contract module provides a basic access control mechanism,
* where a set of addresses are granted access to protected functions.
* These addresses are said the be _tolled_.
*
* Initially, no address is tolled. Through the `kiss(address)` and
* `diss(address)` functions, auth'ed callers are able to toll/de-toll
* addresses. Authentication for these functions is defined via the
* downstream implemented `toll_auth()` function.
*
* This module is used through inheritance. It will make available the
* modifier `toll`, which can be applied to functions to restrict their
* use to only tolled callers.
*/
abstract contract Toll is IToll {
/// @dev Mapping storing whether address is tolled.
/// @custom:invariant Image of mapping is {0, 1}.
/// ∀x ∊ Address: _buds[x] ∊ {0, 1}
/// @custom:invariant Only functions `kiss` and `diss` may mutate the mapping's state.
/// ∀x ∊ Address: preTx(_buds[x]) != postTx(_buds[x])
/// → (msg.sig == "kiss" ∨ msg.sig == "diss")
/// @custom:invariant Mapping's state may only be mutated by authenticated caller.
/// ∀x ∊ Address: preTx(_buds[x]) != postTx(_buds[x])
/// → toll_auth()
mapping(address => uint) private _buds;
/// @dev List of addresses possibly being tolled.
/// @dev May contain duplicates.
/// @dev May contain addresses not being tolled anymore.
/// @custom:invariant Every address being tolled once is element of the list.
/// ∀x ∊ Address: tolled(x) → x ∊ _budsTouched
address[] private _budsTouched;
/// @dev Ensures caller is tolled.
modifier toll() {
assembly ("memory-safe") {
// Compute slot of _buds[msg.sender].
mstore(0x00, caller())
mstore(0x20, _buds.slot)
let slot := keccak256(0x00, 0x40)
// Revert if caller not tolled.
let isTolled := sload(slot)
if iszero(isTolled) {
// Store selector of `NotTolled(address)`.
mstore(0x00, 0xd957b595)
// Store msg.sender.
mstore(0x20, caller())
// Revert with (offset, size).
revert(0x1c, 0x24)
}
}
_;
}
/// @dev Reverts if caller not allowed to access protected function.
/// @dev Must be implemented in downstream contract.
function toll_auth() internal virtual;
/// @inheritdoc IToll
function kiss(address who) external {
toll_auth();
if (_buds[who] == 1) return;
_buds[who] = 1;
_budsTouched.push(who);
emit TollGranted(msg.sender, who);
}
/// @inheritdoc IToll
function diss(address who) external {
toll_auth();
if (_buds[who] == 0) return;
_buds[who] = 0;
emit TollRenounced(msg.sender, who);
}
/// @inheritdoc IToll
function tolled(address who) public view returns (bool) {
return _buds[who] == 1;
}
/// @inheritdoc IToll
/// @custom:invariant Only contains tolled addresses.
/// ∀x ∊ tolled(): _tolled[x]
/// @custom:invariant Contains all tolled addresses.
/// ∀x ∊ Address: _tolled[x] == 1 → x ∊ tolled()
function tolled() public view returns (address[] memory) {
// Initiate array with upper limit length.
address[] memory budsList = new address[](_budsTouched.length);
// Iterate through all possible tolled addresses.
uint ctr;
for (uint i; i < budsList.length; i++) {
// Add address only if still tolled.
if (_buds[_budsTouched[i]] == 1) {
budsList[ctr++] = _budsTouched[i];
}
}
// Set length of array to number of tolled addresses actually included.
assembly ("memory-safe") {
mstore(budsList, ctr)
}
return budsList;
}
/// @inheritdoc IToll
function bud(address who) public view returns (uint) {
return _buds[who];
}
}
dependencies/uscribe-1.3.0/src/IUScribe.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {UPokeData, SchnorrData, ECDSAData} from "./Types.sol";
import {LibSecp256k1} from "./libs/LibSecp256k1.sol";
interface IUScribe {
//--------------------------------------------------------------------------
// Errors
/// @notice Thrown if poke verification failed.
/// @param err The verification error.
error PokeError_VerificationFailed(bytes4 err);
/// @notice Thrown if poke rejected by consumer.
/// @param err The consumer error.
error PokeError_ConsumerRejectedPayload(bytes4 err);
//----------------------------------
// Verification Errors
/// @notice Verification error thrown via `PokeError_VerificationFailed` if
/// poke did not reach bar threshold.
error VerificationError_BarNotReached();
/// @notice Verification error thrown via `PokeError_VerificationFailed` if
/// poke attempted double signing.
error VerificationError_DoubleSigningAttempted();
/// @notice Verification error thrown via `PokeError_VerificationFailed` if
/// poke included invalid validator.
error VerificationError_ValidatorInvalid();
/// @notice Verification error thrown via `PokeError_VerificationFailed` if
/// poke included invalid signature.
error VerificationError_SignatureInvalid();
//--------------------------------------------------------------------------
// Events
/// @notice Emitted when oracle was successfully poked.
/// @param caller The caller's address.
/// @param proofURI Optional URI to validity proof.
event UPoked(address indexed caller, string proofURI);
/// @notice Emitted when new validator lifted for Schnorr verification.
/// @param caller The caller's address.
/// @param validator The validator address lifted.
event ValidatorLiftedSchnorr(
address indexed caller, address indexed validator
);
/// @notice Emitted when validator dropped from Schnorr verification.
/// @param caller The caller's address.
/// @param validator The validator address dropped.
event ValidatorDroppedSchnorr(
address indexed caller, address indexed validator
);
/// @notice Emitted when bar for Schnorr verification updated.
/// @param caller The caller's address.
/// @param oldBar The old bar's value.
/// @param newBar The new bar's value.
event BarUpdatedSchnorr(address indexed caller, uint8 oldBar, uint8 newBar);
/// @notice Emitted when new validator lifted for ECDSA verification.
/// @param caller The caller's address.
/// @param validator The validator address lifted.
event ValidatorLiftedECDSA(
address indexed caller, address indexed validator
);
/// @notice Emitted when validator dropped from ECDSA verification.
/// @param caller The caller's address.
/// @param validator The validator address dropped.
event ValidatorDroppedECDSA(
address indexed caller, address indexed validator
);
/// @notice Emitted when bar for ECDSA verification updated.
/// @param caller The caller's address.
/// @param oldBar The old bar's value.
/// @param newBar The new bar's value.
event BarUpdatedECDSA(address indexed caller, uint8 oldBar, uint8 newBar);
//--------------------------------------------------------------------------
// Poke Functionality
/// @notice Pokes the oracle using Schnorr verification.
/// @param uPokeData The UPokeData being poked.
/// @param schnorrData The SchnorrData proving the `uPokeData`'s integrity.
function poke(
UPokeData calldata uPokeData,
SchnorrData calldata schnorrData
) external;
/// @notice Pokes the oracle using ECDSA verification.
/// @param uPokeData The UPokeData being poked.
/// @param ecdsaDatas The list of ECDSAData proving the `uPokeData`'s
/// integrity.
function poke(UPokeData calldata uPokeData, ECDSAData[] calldata ecdsaDatas)
external;
/// @notice Construct a Chronicle Signed Message.
/// @param scheme The scheme to construct the message for.
/// @param uPokeData The UPokeData to inlcude in the message.
function constructChronicleSignedMessage(
bytes32 scheme,
UPokeData calldata uPokeData
) external view returns (bytes32);
//--------------------------------------------------------------------------
// Auth'ed Functionality
/// @notice Lifts list of public keys `pubKeys` for Schnorr verification.
/// @dev Only callable by auth'ed address.
/// @param pubKeys The list of public keys to lift.
function liftSchnorr(LibSecp256k1.Point[] calldata pubKeys) external;
/// @notice Drops list of validator ids `ids` from Schnorr verification.
/// @dev Only callable by auth'ed address.
/// @param ids The list of validator ids to drop.
function dropSchnorr(uint8[] calldata ids) external;
/// @notice Updates the bar security parameter for Schnorr verification.
/// @dev Only callable by auth'ed address.
/// @param bar The value to update bar to.
function setBarSchnorr(uint8 bar) external;
/// @notice Lifts list of addresses `validators` for ECDSA verification.
/// @dev Only callable by auth'ed address.
/// @param validators The list of addresses to lift.
function liftECDSA(address[] calldata validators) external;
/// @notice Drops list of validator ids `ids` from ECDSA verification.
/// @dev Only callable by auth'ed address.
/// @param ids The list of validator ids to drop.
function dropECDSA(uint8[] calldata ids) external;
/// @notice Updates the bar security parameter for ECDSA verification.
/// @dev Only callable by auth'ed address.
/// @param bar The value to update bar to.
function setBarECDSA(uint8 bar) external;
//--------------------------------------------------------------------------
// Public View Functions
/// @notice Returns the oracle's identifier.
/// @dev The wat is derived from `name()`:
///
/// ```solidity
/// assert(wat() = keccak256(bytes(name())));
/// ```
/// @return bytes32 The oracle's identifier.
function wat() external view returns (bytes32);
/// @notice Returns the oracle's name.
/// @return string The oracle's name.
function name() external view returns (string memory);
/// @notice Returns the timestamp of the latest poke.
/// @dev This timestamp is updated on every poke and allows uniform
/// staleness monitoring accross uscribe instances.
/// @return uint The timestamp of the latest poke.
function latestPoke() external view returns (uint);
/// @notice Returns whether address `who` is a validator for Schnorr
/// verification.
/// @param who The address to check.
/// @return bool True if `who` is a validator for Schnorr verification,
/// false otherwise.
function validatorsSchnorr(address who) external view returns (bool);
/// @notice Returns whether validator id `id` is a validator for Schnorr
/// verification and, if so, the validator's address.
/// @param id The validator id to check.
/// @return bool True if `who` is a validator for Schnorr verification,
/// false otherwise.
/// @return address Address of the validator if `id` is a validator for
/// Schnorr verification, zero address otherwise.
function validatorsSchnorr(uint8 id)
external
view
returns (bool, address);
/// @notice Returns the lift of validator addresses for Schnorr
/// verification.
/// @return address[] The lift of validator addresses for Schnorr
/// verification.
function validatorsSchnorr() external view returns (address[] memory);
/// @notice Returns the bar security parameter for Schnorr verification.
/// @return uint8 The bar security parameter for Schnorr verification.
function barSchnorr() external view returns (uint8);
/// @notice Returns whether address `who` is a validator for ECDSA
/// verification.
/// @param who The address to check.
/// @return bool True if `who` is a validator for ECDSA verification, false
/// otherwise.
function validatorsECDSA(address who) external view returns (bool);
/// @notice Returns whether validator id `id` is a validator for ECDSA
/// verification and, if so, the validator's address.
/// @param id The validator id to check.
/// @return bool True if `who` is a validator for ECDSA verification,
/// false otherwise.
/// @return address Address of the validator if `id` is a validator for
/// ECDSA verification, zero address otherwise.
function validatorsECDSA(uint id) external view returns (bool, address);
/// @notice Returns the lift of validator addresses for ECDSA verification.
/// @return address[] The lift of validator addresses for ECDSA
/// verification.
function validatorsECDSA() external view returns (address[] memory);
/// @notice Returns the bar security parameter for ECDSA verification.
/// @return uint8 The bar security parameter for ECDSA verification.
function barECDSA() external view returns (uint8);
}
dependencies/uscribe-1.3.0/src/IUScribeRouter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
interface IUScribeRouter {
/// @notice Emitted when the UScribe address is updated.
/// @param caller The caller's address.
/// @param oldUScribe The old UScribe address.
/// @param newUScribe The new UScribe address.
event UScribeUpdated(
address indexed caller, address oldUScribe, address newUScribe
);
/// @notice Sets the UScribe address.
/// @param uscribe The address of the UScribe contract.
/// @param wat The wat of the UScribe contract.
/// @dev Reverts if the UScribe contract does not have the expected wat.
function setUScribe(address uscribe, bytes32 wat) external;
/// @notice Returns the UScribe address.
/// @return address The UScribe address.
function uscribe() external view returns (address);
}
dependencies/uscribe-1.3.0/src/Types.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
struct UPokeData {
bytes payload;
string proofURI;
}
struct SchnorrData {
bytes32 signature;
address commitment;
bytes validatorIds;
}
struct ECDSAData {
uint8 v;
bytes32 r;
bytes32 s;
}
dependencies/uscribe-1.3.0/src/UScribeRouter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.24;
import {Auth} from "chronicle-std@v2/auth/Auth.sol";
import {IUScribe} from "./IUScribe.sol";
import {IUScribeRouter} from "./IUScribeRouter.sol";
/**
* @title UScribeRouter
*
* @notice A base router contract for UScribe.
*
* @author Chronicle Labs, Inc
* @custom:security-contact [email protected]
*/
abstract contract UScribeRouter is IUScribeRouter, Auth {
address private __uscribe;
constructor(address initialAuthed) Auth(initialAuthed) {}
/// @inheritdoc IUScribeRouter
function setUScribe(address uscribe_, bytes32 wat) external auth {
require(IUScribe(uscribe_).wat() == wat);
if (__uscribe != uscribe_) {
emit UScribeUpdated(msg.sender, __uscribe, uscribe_);
__uscribe = uscribe_;
}
}
/// @inheritdoc IUScribeRouter
function uscribe() public view returns (address) {
return __uscribe;
}
}
dependencies/uscribe-1.3.0/src/libs/LibSecp256k1.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.16;
///////////////////////////////////////////////////////////////////////////////
//
// Library copied from [email protected]
//
// Reference: https://github.com/chronicleprotocol/scribe/blob/7d2106a265a8d82f259b506c4c8fec42002546ef/src/libs/LibSecp256k1.sol
//
///////////////////////////////////////////////////////////////////////////////
/**
* @title LibSecp256k1
*
* @notice Library for secp256k1 elliptic curve computations
*
* @dev This library was developed to efficiently compute aggregated public
* keys for Schnorr signatures based on secp256k1, i.e. it is _not_ a
* general purpose elliptic curve library!
*
* References to the Ethereum Yellow Paper are based on the following
* version: "BERLIN VERSION beacfbd – 2022-10-24".
*/
library LibSecp256k1 {
using LibSecp256k1 for LibSecp256k1.Point;
using LibSecp256k1 for LibSecp256k1.JacobianPoint;
uint private constant ADDRESS_MASK =
0x000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
// -- Secp256k1 Constants --
//
// Taken from https://www.secg.org/sec2-v2.pdf.
// See section 2.4.1 "Recommended Parameters secp256k1".
uint private constant _A = 0;
uint private constant _B = 7;
uint private constant _P =
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;
/// @dev Returns the order of the group.
function Q() internal pure returns (uint) {
return
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
}
/// @dev Returns the generator G.
/// Note that the generator is also called base point.
function G() internal pure returns (Point memory) {
return Point({
x: 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
y: 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
});
}
/// @dev Returns the zero point.
function ZERO_POINT() internal pure returns (Point memory) {
return Point({x: 0, y: 0});
}
// -- (Affine) Point --
/// @dev Point encapsulates a secp256k1 point in Affine coordinates.
struct Point {
uint x;
uint y;
}
/// @dev Returns the Ethereum address of `self`.
///
/// @dev An Ethereum address is defined as the rightmost 160 bits of the
/// keccak256 hash of the concatenation of the hex-encoded x and y
/// coordinates of the corresponding ECDSA public key.
/// See "Appendix F: Signing Transactions" §134 in the Yellow Paper.
function toAddress(Point memory self) internal pure returns (address) {
address addr;
// Functionally equivalent Solidity code:
// addr = address(uint160(uint(keccak256(abi.encode(self.x, self.y)))));
assembly ("memory-safe") {
addr := and(keccak256(self, 0x40), ADDRESS_MASK)
}
return addr;
}
/// @dev Returns Affine point `self` in Jacobian coordinates.
function toJacobian(Point memory self)
internal
pure
returns (JacobianPoint memory)
{
return JacobianPoint({x: self.x, y: self.y, z: 1});
}
/// @dev Returns whether `self` is the zero point.
function isZeroPoint(Point memory self) internal pure returns (bool) {
return (self.x | self.y) == 0;
}
/// @dev Returns whether `self` is a point on the curve.
///
/// @dev The secp256k1 curve is specified as y² ≡ x³ + ax + b (mod P)
/// where:
/// a = 0
/// b = 7
function isOnCurve(Point memory self) internal pure returns (bool) {
uint left = mulmod(self.y, self.y, _P);
// Note that adding a * x can be waived as ∀x: a * x = 0.
uint right =
addmod(mulmod(self.x, mulmod(self.x, self.x, _P), _P), _B, _P);
return left == right;
}
/// @dev Returns the parity of `self`'s y coordinate.
///
/// @dev The value 0 represents an even y value and 1 represents an odd y
/// value.
/// See "Appendix F: Signing Transactions" in the Yellow Paper.
function yParity(Point memory self) internal pure returns (uint) {
return self.y & 1;
}
// -- Jacobian Point --
/// @dev JacobianPoint encapsulates a secp256k1 point in Jacobian
/// coordinates.
struct JacobianPoint {
uint x;
uint y;
uint z;
}
/// @dev Returns Jacobian point `self` in Affine coordinates.
///
/// @custom:invariant Reverts iff out of gas.
/// @custom:invariant Does not run into an infinite loop.
function toAffine(JacobianPoint memory self)
internal
pure
returns (Point memory)
{
Point memory result;
// Compute z⁻¹, i.e. the modular inverse of self.z.
uint zInv = _invMod(self.z);
// Compute (z⁻¹)² (mod P)
uint zInv_2 = mulmod(zInv, zInv, _P);
// Compute self.x * (z⁻¹)² (mod P), i.e. the x coordinate of given
// Jacobian point in Affine representation.
result.x = mulmod(self.x, zInv_2, _P);
// Compute self.y * (z⁻¹)³ (mod P), i.e. the y coordinate of given
// Jacobian point in Affine representation.
result.y = mulmod(self.y, mulmod(zInv, zInv_2, _P), _P);
return result;
}
/// @dev Adds Affine point `p` to Jacobian point `self`.
///
/// It is the caller's responsibility to ensure given points are on the
/// curve!
///
/// Computation based on: https://www.hyperelliptic.org/EFD/g1p/auto-shortw-jacobian.html#addition-madd-2007-bl.
///
/// Note that the formula assumes z2 = 1, which always holds if z2's
/// point is given in Affine coordinates.
///
/// Note that eventhough the function is marked as pure, to be
/// understood as only being dependent on the input arguments, it
/// nevertheless has side effects by writing the result into the
/// `self` memory variable.
///
/// @custom:invariant Only mutates `self` memory variable.
/// @custom:invariant Reverts iff out of gas.
/// @custom:invariant Uses constant amount of gas.
function addAffinePoint(JacobianPoint memory self, Point memory p)
internal
pure
{
// Addition formula:
// x = r² - j - (2 * v) (mod P)
// y = (r * (v - x)) - (2 * y1 * j) (mod P)
// z = (z1 + h)² - z1² - h² (mod P)
//
// where:
// r = 2 * (s - y1) (mod P)
// j = h * i (mod P)
// v = x1 * i (mod P)
// h = u - x1 (mod P)
// s = y2 * z1³ (mod P) Called s2 in reference
// i = 4 * h² (mod P)
// u = x2 * z1² (mod P) Called u2 in reference
//
// and:
// x1 = self.x
// y1 = self.y
// z1 = self.z
// x2 = p.x
// y2 = p.y
//
// Note that in order to save memory allocations the result is stored
// in the self variable, i.e. the following holds true after the
// functions execution:
// x = self.x
// y = self.y
// z = self.z
// Cache self's coordinates on stack.
uint x1 = self.x;
uint y1 = self.y;
uint z1 = self.z;
// Compute z1_2 = z1² (mod P)
// = z1 * z1 (mod P)
uint z1_2 = mulmod(z1, z1, _P);
// Compute h = u - x1 (mod P)
// = u + (P - x1) (mod P)
// = x2 * z1² + (P - x1) (mod P)
//
// Unchecked because the only protected operation performed is P - x1
// where x1 is guaranteed by the caller to be an x coordinate belonging
// to a point on the curve, i.e. being less than P.
uint h;
unchecked {
h = addmod(mulmod(p.x, z1_2, _P), _P - x1, _P);
}
// Compute h_2 = h² (mod P)
// = h * h (mod P)
uint h_2 = mulmod(h, h, _P);
// Compute i = 4 * h² (mod P)
uint i = mulmod(4, h_2, _P);
// Compute z = (z1 + h)² - z1² - h² (mod P)
// = (z1 + h)² - z1² + (P - h²) (mod P)
// = (z1 + h)² + (P - z1²) + (P - h²) (mod P)
// ╰───────╯ ╰───────╯ ╰──────╯
// left mid right
//
// Unchecked because the only protected operations performed are
// subtractions from P where the subtrahend is the result of a (mod P)
// computation, i.e. the subtrahend being guaranteed to be less than P.
unchecked {
uint left = mulmod(addmod(z1, h, _P), addmod(z1, h, _P), _P);
uint mid = _P - z1_2;
uint right = _P - h_2;
self.z = addmod(left, addmod(mid, right, _P), _P);
}
// Compute v = x1 * i (mod P)
uint v = mulmod(x1, i, _P);
// Compute j = h * i (mod P)
uint j = mulmod(h, i, _P);
// Compute r = 2 * (s - y1) (mod P)
// = 2 * (s + (P - y1)) (mod P)
// = 2 * ((y2 * z1³) + (P - y1)) (mod P)
// = 2 * ((y2 * z1² * z1) + (P - y1)) (mod P)
//
// Unchecked because the only protected operation performed is P - y1
// where y1 is guaranteed by the caller to be an y coordinate belonging
// to a point on the curve, i.e. being less than P.
uint r;
unchecked {
r = mulmod(
2,
addmod(mulmod(p.y, mulmod(z1_2, z1, _P), _P), _P - y1, _P),
_P
);
}
// Compute x = r² - j - (2 * v) (mod P)
// = r² - j + (P - (2 * v)) (mod P)
// = r² + (P - j) + (P - (2 * v)) (mod P)
// ╰─────╯ ╰───────────╯
// mid right
//
// Unchecked because the only protected operations performed are
// subtractions from P where the subtrahend is the result of a (mod P)
// computation, i.e. the subtrahend being guaranteed to be less than P.
unchecked {
uint r_2 = mulmod(r, r, _P);
uint mid = _P - j;
uint right = _P - mulmod(2, v, _P);
self.x = addmod(r_2, addmod(mid, right, _P), _P);
}
// Compute y = (r * (v - x)) - (2 * y1 * j) (mod P)
// = (r * (v - x)) + (P - (2 * y1 * j)) (mod P)
// = (r * (v + (P - x))) + (P - (2 * y1 * j)) (mod P)
// ╰─────────────────╯ ╰────────────────╯
// left right
//
// Unchecked because the only protected operations performed are
// subtractions from P where the subtrahend is the result of a (mod P)
// computation, i.e. the subtrahend being guaranteed to be less than P.
unchecked {
uint left = mulmod(r, addmod(v, _P - self.x, _P), _P);
uint right = _P - mulmod(2, mulmod(y1, j, _P), _P);
self.y = addmod(left, right, _P);
}
}
// -- Private Helpers --
/// @dev Returns the modular inverse of `x` for modulo `_P`.
///
/// It is the caller's responsibility to ensure `x` is less than `_P`!
///
/// The modular inverse of `x` is x⁻¹ such that x * x⁻¹ ≡ 1 (mod P).
///
/// @dev Modified from Jordi Baylina's [ecsol](https://github.com/jbaylina/ecsol/blob/c2256afad126b7500e6f879a9369b100e47d435d/ec.sol#L51-L67).
///
/// @custom:invariant Reverts iff out of gas.
/// @custom:invariant Does not run into an infinite loop.
function _invMod(uint x) private pure returns (uint) {
uint t;
uint q;
uint newT = 1;
uint r = _P;
assembly ("memory-safe") {
// Implemented in assembly to circumvent division-by-zero
// and over-/underflow protection.
//
// Functionally equivalent Solidity code:
// while (x != 0) {
// q = r / x;
// (t, newT) = (newT, addmod(t, (_P - mulmod(q, newT, _P)), _P));
// (r, x) = (x, r - (q * x));
// }
//
// For the division r / x, x is guaranteed to not be zero via the
// loop condition.
//
// The subtraction of form P - mulmod(_, _, P) is guaranteed to not
// underflow due to the subtrahend being a (mod P) result,
// i.e. the subtrahend being guaranteed to be less than P.
//
// The subterm q * x is guaranteed to not overflow because
// q * x ≤ r due to q = ⎣r / x⎦.
//
// The term r - (q * x) is guaranteed to not underflow because
// q * x ≤ r and therefore r - (q * x) ≥ 0.
for {} x {} {
q := div(r, x)
let tmp := t
t := newT
newT := addmod(tmp, sub(_P, mulmod(q, newT, _P)), _P)
tmp := r
r := x
x := sub(tmp, mul(q, x))
}
}
return t;
}
}
src/IReader.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IChronicleVAO_Reader {
/// @notice Returns the oracle's current value.
/// @dev Reverts if:
/// - Not yet poked
/// @return val The oracle's current value.
function read() external view returns (uint val);
/// @notice Returns the oracle's current value.
/// @return ok True if previously poked, false otherwise.
/// @return val The oracle's current value if it exists, zero otherwise.
function tryRead() external view returns (bool ok, uint val);
/// @notice Returns the oracle's current value and its age.
/// @dev Reverts if:
/// - Not yet poked
/// @return val The oracle's current value.
/// @return age The value's age.
function readWithAge() external view returns (uint val, uint age);
/// @notice Returns the oracle's current value and its age.
/// @return ok True if previously poked, false otherwise.
/// @return val The oracle's current value if it exists, zero otherwise.
/// @return age The value's age if value exists, zero otherwise.
function tryReadWithAge()
external
view
returns (bool ok, uint val, uint age);
}
src/Router.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.28;
import {Toll} from "chronicle-std@v2/toll/Toll.sol";
import {UScribeRouter} from "uscribe@v1/UScribeRouter.sol";
import {IChronicleVAO_Reader as IReader} from "./IReader.sol";
/**
* @title ChronicleVAO_Router
*
* @author Chronicle Labs, Inc
* @custom:security-contact [email protected]
*/
contract ChronicleVAO_Router is IReader, UScribeRouter, Toll {
constructor(address initialAuthed) UScribeRouter(initialAuthed) {}
/// @dev Defines authorization for IToll's authenticated functions.
function toll_auth() internal override(Toll) auth {}
// ------------------------------------------------------------------------
// IReader Functionality
//// @inheritdoc IVAOReader
function read() external view toll returns (uint) {
return IReader(uscribe()).read();
}
//// @inheritdoc IVAOReader
function tryRead() external view toll returns (bool, uint) {
return IReader(uscribe()).tryRead();
}
//// @inheritdoc IVAOReader
function readWithAge() external view toll returns (uint, uint) {
return IReader(uscribe()).readWithAge();
}
//// @inheritdoc IVAOReader
function tryReadWithAge() external view toll returns (bool, uint, uint) {
return IReader(uscribe()).tryReadWithAge();
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 10000,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
"forge-std@v1/=dependencies/forge-std-1.9.7/src/",
"chronicle-std@v2/=dependencies/chronicle-std-2.1.0/src/",
"uscribe@v1/=dependencies/uscribe-1.3.0/src/",
"uscribe-tests@v1/=dependencies/uscribe-1.3.0/test/",
"greenhouse@v1/=dependencies/greenhouse-1.0.0/src/",
"openzeppelin@v5/=dependencies/openzeppelin-5.2.0/contracts/",
"@openzeppelin/contracts/=dependencies/openzeppelin-5.2.0/contracts/",
"chronicle-std-2.1.0/=dependencies/chronicle-std-2.1.0/",
"chronicle-std/=dependencies/greenhouse-1.0.0/lib/chronicle-std/",
"ds-test/=dependencies/chronicle-std-2.1.0/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=dependencies/openzeppelin-5.2.0/lib/erc4626-tests/",
"forge-std-1.9.7/=dependencies/forge-std-1.9.7/src/",
"forge-std/=dependencies/openzeppelin-5.2.0/lib/forge-std/src/",
"greenhouse-1.0.0/=dependencies/greenhouse-1.0.0/",
"halmos-cheatcodes/=dependencies/openzeppelin-5.2.0/lib/halmos-cheatcodes/src/",
"openzeppelin-5.2.0/=dependencies/openzeppelin-5.2.0/",
"uscribe-1.3.0/=dependencies/uscribe-1.3.0/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.