Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/witnet randomness v2 #415

Merged
merged 35 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
985ebb6
feat: IWitnetFeedAdmin.baseFeeOverheadPercentage()
guidiaz Mar 15, 2024
b4a20a9
refactor: UsingWitnetRandomness -> WitnetRandomnessConsumer
guidiaz Mar 15, 2024
c5c51e4
feat: WitnetRandomness v2.0
guidiaz Mar 15, 2024
dcee363
chore: update README
guidiaz Mar 15, 2024
2d4461f
chore: deploy/verify scripts for randomness appliance
guidiaz Mar 15, 2024
a57713a
feat(wrb): limit max acceptable reward
guidiaz Mar 15, 2024
41f6741
fix(rng): estimateRandomizeFee by providing the witnetRadHash
guidiaz Mar 15, 2024
e4dd342
chore: fmt!
guidiaz Mar 15, 2024
cf1386a
chore: bump package version to 2.0.8
guidiaz Mar 15, 2024
d14e890
feat: deploy WitnetRandomness only if explicitly specified or present…
guidiaz Mar 15, 2024
d163760
chore: upgrade WPF to v2.0.8 on optimism:sepolia
guidiaz Mar 15, 2024
5ea91b7
chore: upgrade WRB to v2.0.8 on optimism:sepolia
guidiaz Mar 15, 2024
5f305d6
chore: deploy WitnetRandomnessV20 on optimism:sepolia
guidiaz Mar 15, 2024
4588b66
chore: verify WSB on optimism:sepolia into etherscan and sourcify
guidiaz Mar 15, 2024
71f3a8b
feat: package script verify:apps
guidiaz Mar 15, 2024
e67ba95
chore: declare WitnetRandomness to be IWitnetOracleEvents emitter
guidiaz Mar 15, 2024
9b5f641
fix(rng): recursiveness on fetchRandomness*
guidiaz Mar 15, 2024
d473c35
feat: implement WitnetOracle.getQueryEvmReward(uint256)
guidiaz Mar 19, 2024
1512f25
chore: upgrade WRB on optimism:sepolia
guidiaz Mar 19, 2024
20419ab
refactor: WitnetRandomnessV20 -> WitnetRandomnessV2
guidiaz Mar 19, 2024
7b7dda8
fix/feat: reported callbacks requires specific WitnetV2.ResponseStatu…
guidiaz Mar 19, 2024
703351a
chore: upgrade wrb on optimism:sepolia
guidiaz Mar 19, 2024
93eaeb1
chore: unindex query ids on IWitnetOracleEvents
guidiaz Mar 19, 2024
04b5589
feat(rng): ensure that different block number will always be assigned…
guidiaz Mar 21, 2024
94c621c
chore(rng): optimize required storage for human-readable revert messages
guidiaz Mar 21, 2024
e7121c9
chore: removed currently unused witnet 2.0 protocol constants
guidiaz Mar 21, 2024
4468d28
feat(wrb): getQueryResultCborbytes
guidiaz Mar 21, 2024
4ebd46c
chore: optimize framework storage footprint for human-readable revert…
guidiaz Mar 21, 2024
03de541
chore: upgrade optimism:sepolia
guidiaz Mar 21, 2024
540386c
chore: refactor WitnetV2.randomUint32 -> *.randomUniformUint32
guidiaz Mar 22, 2024
2728fdd
refactor: WitnetRandomnessConsumer -> WitnetRandomnessRequestConsumer
guidiaz Mar 22, 2024
7e65127
chore: IWitnetRandomnessEvents
guidiaz Mar 22, 2024
b69481f
feat: UsingWitnetRandomness abstract contract
guidiaz Mar 22, 2024
ddc33da
feat: WitnetMockedRandomness
guidiaz Mar 22, 2024
21c62e8
chore: export WitnetRandomnessV2 address
guidiaz Mar 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# witnet-solidity-bridge

Open repository containing the smart contracts composing the **Witnet Solidity Bridge** framework. This framework enables Solidity developers and smart contracts operating in a long range of EVM-compatible chains to interact with the [Witnet Oracle Blockchain](https://witnet.io) for retrieving and aggregating offchain public data, and randomness.
Solidity source code of the smart contracts composing the **Witnet EVM Bridge** framework. This framework enables smart contracts operating in a long range of EVM-compatible chains to interact with the [Witnet Oracle Blockchain](https://witnet.io) for retrieving and aggregating offchain public data, or as an entropy source for randomness generation.

## Install the package

`$ pnpm install`

## Deploy the whole WSB framework on a new chain
## Deploying the Witnet EVM Bridge on a new chain

### Pre-assessment

Expand All @@ -29,7 +29,7 @@ Should any artifact require customized contract implementations:

`$ pnpm run migrate <ecosytem>:<chain-name>`

## Upgrade WSB components on an existing chain
## Upgrding the Witnet EVM Bridge on an existing chain

When modifying the existing source code, or the contents of `settings/artifacts` or `settings/specs`, you may need to upgrade some of the artifacts on certain networks. Just add the `--artifacts` parameter and a comma-separated list of the artifacts you need to upgrade. For instance:

Expand All @@ -44,8 +44,43 @@ Reasons for an upgrade to fail:
- You're attempting to upgrade a contract with the same implementation logic as it currently has.
- The parameters passed to the upgrade call, as specified in `settings/specs` are not accepted for some reason (see actual revert message for further info).

## Exported assets

- [Deployed addresses.]("./migrations/addresses.json")
- [Supported chains.]("./settings/networks/index.js")
## Package exported modules

### `require("witnet-solidity-bridge")`
Javacript methods and resources:

- List of supported EVM ecosystems:
- `supportedEcosystems()`
- List of supported EVM chains:
- `supportedNetworks()`
- WEB addresses at a given chain:
- `getAddresses(network)`
- WEB artifacts:
- `assets.WitnetOracle`
- `assets.WitnetPriceFeeds`
- `assets.WitnetPriceRouteSolver`
- `assets.WitnetRequest`
- `assets.WitnetRequestBytecodes`
- `assets.WitnetRequestFactory`
- `assets.WitnetRequestTemplate`
- `assets.WitnetUpgrableBase`

### `require("witnet-solidity-bridge/utils")`

Javascript utils methods:

- `fromAscii(str)`
- `getRealmNetworkFromArgs()`
- `getRealmNetworkFromString()`
- `getWitnetArtifactsFromArgs()`
- `getWitnetRequestMethodString(method)`
- `isDryRun(network)`
- `isNullAddress(addr)`
- `padLeft(str, char, size)`
- `prompt(text)`
- `readJsonFromFile(filename)`
- `overwriteJsonFile(filname, extra)`
- `traceHeader(header)`
- `traceTx(tx)`
- `traceVerify(network, verifyArgs)`

6 changes: 3 additions & 3 deletions contracts/apps/WitnetFeeds.sol → contracts/WitnetFeeds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

pragma solidity >=0.7.0 <0.9.0;

import "../interfaces/IFeeds.sol";
import "../interfaces/IWitnetFeeds.sol";
import "../interfaces/IWitnetFeedsAdmin.sol";
import "./interfaces/IFeeds.sol";
import "./interfaces/IWitnetFeeds.sol";
import "./interfaces/IWitnetFeedsAdmin.sol";

import "ado-contracts/contracts/interfaces/IERC2362.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/WitnetPriceFeeds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pragma solidity >=0.7.0 <0.9.0;

import "./apps/WitnetFeeds.sol";
import "./WitnetFeeds.sol";

import "./interfaces/IWitnetPriceFeeds.sol";
import "./interfaces/IWitnetPriceSolverDeployer.sol";
Expand Down
15 changes: 15 additions & 0 deletions contracts/WitnetRandomness.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0 <0.9.0;

import "./interfaces/IWitnetOracleEvents.sol";
import "./interfaces/IWitnetRandomness.sol";

abstract contract WitnetRandomness
is
IWitnetOracleEvents,
IWitnetRandomness
{
function class() virtual external view returns (string memory);
function specs() virtual external view returns (bytes4);
}
12 changes: 2 additions & 10 deletions contracts/apps/UsingWitnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract UsingWitnet
/// @dev as to deal with volatility of evmGasPrice and evmWitPrice during the live time of
/// @dev a data request (since being posted until a result gets reported back), at both the EVM and
/// @dev the Witnet blockchain levels, respectivelly.
uint16 private __witnetBaseFeeOverheadPercentage;
uint16 internal __witnetBaseFeeOverheadPercentage;

/// @param _wrb Address of the WitnetOracle contract.
constructor(WitnetOracle _wrb) {
Expand Down Expand Up @@ -71,7 +71,7 @@ abstract contract UsingWitnet
returns (uint256)
{
return (
(100 + _witnetBaseFeeOverheadPercentage())
(100 + __witnetBaseFeeOverheadPercentage)
* __witnet.estimateBaseFee(tx.gasprice, _resultMaxSize)
) / 100;
}
Expand All @@ -89,12 +89,4 @@ abstract contract UsingWitnet
{
return __witnet.getQueryResultError(_witnetQueryId);
}

function _witnetBaseFeeOverheadPercentage() virtual internal view returns (uint16) {
return __witnetBaseFeeOverheadPercentage;
}

function __witnetSetBaseFeeOverheadPercentage(uint16 _baseFeeOverheadPercentage) virtual internal {
__witnetBaseFeeOverheadPercentage = _baseFeeOverheadPercentage;
}
}
2 changes: 1 addition & 1 deletion contracts/apps/UsingWitnetRequest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract contract UsingWitnetRequest
dataRequest = _witnetRequest;
__witnetQueryResultMaxSize = _witnetRequest.resultDataMaxSize();
__witnetRequestRadHash = _witnetRequest.radHash();
__witnetSetBaseFeeOverheadPercentage(_baseFeeOverheadPercentage);
__witnetBaseFeeOverheadPercentage = _baseFeeOverheadPercentage;
}

function _witnetEstimateEvmReward()
Expand Down
2 changes: 1 addition & 1 deletion contracts/apps/UsingWitnetRequestTemplate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract contract UsingWitnetRequestTemplate
);
dataRequestTemplate = _witnetRequestTemplate;
__witnetQueryResultMaxSize = _witnetRequestTemplate.resultDataMaxSize();
__witnetSetBaseFeeOverheadPercentage(_baseFeeOverheadPercentage);
__witnetBaseFeeOverheadPercentage = _baseFeeOverheadPercentage;
}

function _witnetBuildRadHash(string[][] memory _witnetRequestArgs)
Expand Down
4 changes: 2 additions & 2 deletions contracts/apps/WitnetConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract contract WitnetConsumer

function _witnetEstimateEvmReward() virtual internal view returns (uint256) {
return (
(100 + _witnetBaseFeeOverheadPercentage())
(100 + __witnetBaseFeeOverheadPercentage)
* __witnet.estimateBaseFeeWithCallback(
tx.gasprice,
_witnetCallbackGasLimit()
Expand All @@ -67,7 +67,7 @@ abstract contract WitnetConsumer
returns (uint256)
{
return (
(100 + _witnetBaseFeeOverheadPercentage())
(100 + __witnetBaseFeeOverheadPercentage)
* __witnet.estimateBaseFeeWithCallback(
tx.gasprice,
_callbackGasLimit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pragma experimental ABIEncoderV2;
import "./WitnetConsumer.sol";
import "../WitnetRequest.sol";

abstract contract UsingWitnetRandomness
abstract contract WitnetRandomnessConsumer
is
WitnetConsumer
{
Expand All @@ -30,12 +30,11 @@ abstract contract UsingWitnetRandomness
{
// On-chain building of the Witnet Randomness Request:
{
WitnetRequestFactory _factory = witnet().factory();
WitnetRequestBytecodes _registry = witnet().registry();
// Build own Witnet Randomness Request:
bytes32[] memory _retrievals = new bytes32[](1);
_retrievals[0] = _registry.verifyRadonRetrieval(
Witnet.RadonDataRequestMethods.Rng,
Witnet.RadonDataRequestMethods.RNG,
"", // no url
"", // no body
new string[2][](0), // no headers
Expand All @@ -50,17 +49,15 @@ abstract contract UsingWitnetRandomness
opcode: Witnet.RadonReducerOpcodes.ConcatenateAndHash,
filters: _filters // no filters
}));
WitnetRequestTemplate _template = WitnetRequestTemplate(_factory.buildRequestTemplate(
__witnetRandomnessRadHash = _registry.verifyRadonRequest(
_retrievals,
_aggregator,
_tally,
32 // 256 bits of pure entropy ;-)
));
__witnetRandomnessRadHash = WitnetRequest(
_template.buildRequest(new string[][](_retrievals.length))
).radHash();
32, // 256 bits of pure entropy ;-)
new string[][](_retrievals.length)
);
}
__witnetSetBaseFeeOverheadPercentage(_baseFeeOverheadPercentage);
__witnetBaseFeeOverheadPercentage = _baseFeeOverheadPercentage;
}

function _witnetEstimateEvmReward() virtual override internal view returns (uint256) {
Expand Down
Loading