Verified contractExactMIT
ScenarioImplementation
Address0xeb4e1a8605d2f5784ecf15a6265fd376776b783c
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,385,006
- Creation transaction
- 0xf932639686…ea580907ae
2 files
- src/Scenario.solmain7.49 KB
- src/Fixtures.sol4.8 KB
src/Scenario.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
import {IRegistry, TestToken} from "./Fixtures.sol";
/// Cooperative storage convention, not a sandbox for untrusted implementations.
library ScenarioStorage {
bytes32 internal constant IMPLEMENTATION = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
struct Control {
address controller;
IRegistry registry;
bytes32 active;
}
struct Application {
uint256 value;
uint256 work;
TestToken token;
bool initialized;
}
function namespace(string memory name) internal pure returns (bytes32) {
return keccak256(abi.encode(uint256(keccak256(bytes(name))) - 1)) & ~bytes32(uint256(0xff));
}
function control() internal pure returns (Control storage s) {
bytes32 slot = namespace("titan.scenario.control.v1");
assembly { s.slot := slot }
}
function context(bytes32 run, bytes32 schema, bytes32 attempt) internal pure returns (bytes32) {
return keccak256(abi.encode(namespace("titan.scenario.application.v1"), run, schema, attempt));
}
function application(bytes32 slot) internal pure returns (Application storage s) {
assembly { s.slot := slot }
}
}
abstract contract ScenarioControlled {
modifier controlled() {
require(msg.sender == ScenarioStorage.control().controller, "test owner only");
_;
}
modifier credible(bytes32 context_, uint256 deadline) {
require(block.number <= deadline, "test attempt expired");
ScenarioStorage.Control storage c = ScenarioStorage.control();
require(context_ != bytes32(0) && c.active == context_, "wrong context");
require(c.registry.isCredibleBlock(), "marker missing");
_;
}
}
/// One protected adopter, with a fixed control namespace and direct ABI forwarding.
contract ScenarioProxy is ScenarioControlled {
event ContextStarted(bytes32 indexed run, bytes32 indexed schema, bytes32 indexed attempt, bytes32 context);
event ContextEnded(bytes32 indexed context);
constructor(address registry_, address controller_, address implementation_) {
require(controller_ != address(0) && registry_.code.length > 0, "invalid control");
ScenarioStorage.Control storage c = ScenarioStorage.control();
c.controller = controller_;
c.registry = IRegistry(registry_);
_upgrade(implementation_);
}
function owner() external view returns (address) {
return ScenarioStorage.control().controller;
}
function registry() external view returns (IRegistry) {
return ScenarioStorage.control().registry;
}
function activeContext() external view returns (bytes32) {
return ScenarioStorage.control().active;
}
function contextSlot(bytes32 run, bytes32 schema, bytes32 attempt) external pure returns (bytes32) {
return ScenarioStorage.context(run, schema, attempt);
}
function implementation() external view returns (address result) {
bytes32 slot = ScenarioStorage.IMPLEMENTATION;
assembly { result := sload(slot) }
}
// The runner retires all old assertions and settles all nonces before these controls.
function beginContext(bytes32 run, bytes32 schema, bytes32 attempt, address token) external controlled {
ScenarioStorage.Control storage c = ScenarioStorage.control();
require(c.active == bytes32(0), "context still active");
require(run != bytes32(0) && schema != bytes32(0) && attempt != bytes32(0), "empty identity");
bytes32 slot = ScenarioStorage.context(run, schema, attempt);
ScenarioStorage.Application storage s = ScenarioStorage.application(slot);
require(!s.initialized, "attempt already used");
require(token == address(0) || token.code.length > 0, "token missing");
s.initialized = true;
s.token = TestToken(token);
c.active = slot;
emit ContextStarted(run, schema, attempt, slot);
}
function endContext(bytes32 context_) external controlled {
require(context_ != bytes32(0) && ScenarioStorage.control().active == context_, "wrong context");
ScenarioStorage.control().active = bytes32(0);
emit ContextEnded(context_);
}
function configureImplementation(address implementation_) external controlled {
require(ScenarioStorage.control().active == bytes32(0), "context still active");
_upgrade(implementation_);
}
function upgradeTo(bytes32 context_, address implementation_, uint256 deadline)
external
controlled
credible(context_, deadline)
{
_upgrade(implementation_);
}
function _upgrade(address implementation_) private {
require(implementation_.code.length > 0, "implementation missing");
bytes32 slot = ScenarioStorage.IMPLEMENTATION;
assembly { sstore(slot, implementation_) }
}
fallback() external {
bytes32 slot = ScenarioStorage.IMPLEMENTATION;
assembly {
calldatacopy(0, 0, calldatasize())
let ok := delegatecall(gas(), sload(slot), 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if iszero(ok) { revert(0, returndatasize()) }
return(0, returndatasize())
}
}
}
contract ScenarioImplementation is ScenarioControlled {
event Executed(uint256 indexed sequence, uint256 work, uint256 blockNumber);
function value() external view returns (uint256) {
return ScenarioStorage.application(ScenarioStorage.control().active).value;
}
function work() external view returns (uint256) {
return ScenarioStorage.application(ScenarioStorage.control().active).work;
}
function stateAt(bytes32 run, bytes32 schema, bytes32 attempt) external view returns (uint256, uint256, address) {
ScenarioStorage.Application storage s =
ScenarioStorage.application(ScenarioStorage.context(run, schema, attempt));
return (s.value, s.work, address(s.token));
}
function set(bytes32 context_, uint256 value_, uint256 deadline) external controlled credible(context_, deadline) {
ScenarioStorage.Application storage s = ScenarioStorage.application(context_);
s.value = value_;
emit Executed(value_, s.work, block.number);
}
function step(bytes32 context_, uint256 expected, uint256 work_, uint256 deadline)
external
controlled
credible(context_, deadline)
{
ScenarioStorage.Application storage s = ScenarioStorage.application(context_);
require(s.value == expected, "predecessor missing");
require(work_ <= 300000, "work limit");
s.work = work_;
s.value = expected + 1;
emit Executed(s.value, work_, block.number);
}
function withdraw(bytes32 context_, uint256 amount, uint256 deadline)
external
controlled
credible(context_, deadline)
{
require(ScenarioStorage.application(context_).token.transfer(msg.sender, amount), "transfer failed");
}
function deposit(bytes32 context_, uint256 amount, uint256 deadline)
external
controlled
credible(context_, deadline)
{
require(
ScenarioStorage.application(context_).token.transferFrom(msg.sender, address(this), amount),
"transfer failed"
);
}
}
src/Fixtures.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
interface IRegistry {
function isCredibleBlock() external view returns (bool);
function lastCredibleBlock() external view returns (uint256);
}
abstract contract Guarded {
address public immutable owner;
IRegistry public immutable registry;
constructor(address registry_, address owner_) {
registry = IRegistry(registry_);
owner = owner_;
}
modifier controlled() {
require(msg.sender == owner, "test owner only");
_;
}
modifier credible(uint256 deadline) {
require(block.number <= deadline, "test attempt expired");
require(registry.isCredibleBlock(), "marker missing");
_;
}
}
contract TestToken {
string public constant name = "Titan Integration Test Token";
string public constant symbol = "TITEST";
uint8 public constant decimals = 0;
address public immutable owner;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
constructor(address owner_) {
owner = owner_;
}
function mint(address to, uint256 amount) external {
require(msg.sender == owner, "test owner only");
balanceOf[to] += amount;
emit Transfer(address(0), to, amount);
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
allowance[from][msg.sender] -= amount;
_transfer(from, to, amount);
return true;
}
function _transfer(address from, address to, uint256 amount) private {
balanceOf[from] -= amount;
balanceOf[to] += amount;
emit Transfer(from, to, amount);
}
}
contract FlowVault is Guarded {
TestToken public immutable token;
constructor(address registry_, address owner_, address token_) Guarded(registry_, owner_) {
token = TestToken(token_);
}
function withdraw(uint256 amount, uint256 deadline) external controlled credible(deadline) {
require(token.transfer(owner, amount), "transfer failed");
}
function deposit(uint256 amount, uint256 deadline) external controlled credible(deadline) {
require(token.transferFrom(owner, address(this), amount), "transfer failed");
}
}
contract Probe is Guarded {
uint256 public value; // slot 0: the lifecycle assertion watches this.
uint256 public work; // slot 1: requested gas burn per load assertion.
event Executed(uint256 indexed sequence, uint256 work, uint256 blockNumber);
constructor(address registry_, address owner_) Guarded(registry_, owner_) {}
function set(uint256 value_, uint256 deadline) external controlled credible(deadline) {
value = value_;
emit Executed(value_, work, block.number);
}
function step(uint256 expected, uint256 work_, uint256 deadline) external controlled credible(deadline) {
require(value == expected, "predecessor missing");
require(work_ <= 300000, "work limit");
work = work_;
value = expected + 1;
emit Executed(value, work_, block.number);
}
}
contract Implementation {
uint256 public immutable version;
constructor(uint256 version_) {
version = version_;
}
}
contract TestProxy is Guarded {
bytes32 private constant SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
constructor(address registry_, address owner_, address implementation_) Guarded(registry_, owner_) {
assembly { sstore(SLOT, implementation_) }
}
function implementation() external view returns (address result) {
assembly { result := sload(SLOT) }
}
function upgradeTo(address implementation_, uint256 deadline) external controlled credible(deadline) {
require(implementation_.code.length > 0, "implementation missing");
assembly { sstore(SLOT, implementation_) }
}
fallback() external {
assembly {
calldatacopy(0, 0, calldatasize())
let ok := delegatecall(gas(), sload(SLOT), 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if iszero(ok) { revert(0, returndatasize()) }
return(0, returndatasize())
}
}
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"credible-std/=../../credible-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.