Skip to content

Commit

Permalink
Merge branch 'develop' into miguel/nalgebra_dep
Browse files Browse the repository at this point in the history
  • Loading branch information
fmiguelgarcia committed Jul 25, 2023
2 parents dfc2bfa + dd2306a commit c11a4df
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 116 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ jobs:

- name: Generate test code coverage report
run: |
df -h
sudo apt-get autoremove
sudo apt-get clean
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
cargo +stable install --force grcov
grcov . -s . --binary-path ./target/release/ -t lcov --branch --ignore-not-existing -o lcov.info
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions avail-subxt/examples/accounts_from_mnemonics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use anyhow::Result;
use avail_subxt::{api, build_client, primitives::AvailExtrinsicParams, AvailConfig, Opts};
//use sp_core::crypto::Pair as _;
// use sp_keyring::sr25519::sr25519::{self, Pair};
use structopt::StructOpt;
use subxt::{
ext::sp_core::{sr25519::Pair, Pair as _},
Expand Down
4 changes: 2 additions & 2 deletions avail-subxt/examples/max_block_submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use subxt::tx::PairSigner;

/// This example attempts to submit data to fill the entire block. Note that this doesn't guarantee
/// that the block will be filled, but if you submit more than a full block, then it will spill over
/// to the next block. The limit for the transaction is currently set to 16 kB, and limit for the block
/// to the next block. The limit for the transaction is currently set to 512 kB, and limit for the block
/// is 2 MB, so this means 128 data transactions are needed to fill the block. Depending on the network,
/// it may not be possible to transfer so many in 20 s (the default block time)
Expand All @@ -24,7 +24,7 @@ async fn main() -> Result<()> {

let signer = PairSigner::new(AccountKeyring::Alice.pair());
let size: usize = 2 * 1024 * 1024;
let max_size: usize = 16 * 1024;
let max_size: usize = 512 * 1024;
let num_chunks = size / max_size;
let extrinsic_params = AvailExtrinsicParams::new_with_app_id(1.into());
let start = Instant::now();
Expand Down
58 changes: 55 additions & 3 deletions examples/validium/abi/ValidiumContract.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"inputs": [
{
Expand All @@ -18,7 +37,7 @@
},
{
"internalType": "uint256",
"name": "leafIndex",
"name": "index",
"type": "uint256"
},
{
Expand All @@ -31,7 +50,7 @@
"outputs": [
{
"internalType": "bool",
"name": "",
"name": "isMember",
"type": "bool"
}
],
Expand All @@ -57,6 +76,26 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand All @@ -69,5 +108,18 @@
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
]
65 changes: 39 additions & 26 deletions examples/validium/contracts/ValidiumContract.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
pragma solidity 0.8.15;
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.19;

import "@openzeppelin/contracts/access/Ownable.sol";

contract DataAvailabilityRouter {
mapping(uint32 => bytes32) public roots;
}

contract ValidiumContract {

DataAvailabilityRouter router;
contract ValidiumContract is Ownable {
DataAvailabilityRouter private router;

function setRouter(
address _router
) public {
) public onlyOwner {
router = DataAvailabilityRouter(_router);
}

Expand All @@ -22,33 +24,44 @@ contract ValidiumContract {

function checkDataRootMembership(
uint32 blockNumber,
bytes32[] memory proof,
bytes32[] calldata proof,
uint256 numberOfLeaves,
uint256 leafIndex,
uint256 index,
bytes32 leaf
) public view returns (bool) {
if (leafIndex >= numberOfLeaves) {
return false;
}

uint256 position = leafIndex;
uint256 width = numberOfLeaves;
) public view returns (bool isMember) {
// if the proof is of size n, the tree height will be n+1
// in a tree of height n+1, max possible leaves are 2^n
require(index < numberOfLeaves, "INVALID_LEAF_INDEX");
// refuse to accept padded leaves as proof
require(leaf != bytes32(0), "INVALID_LEAF");

bytes32 computedHash = leaf;
bytes32 rootHash = getDataRoot(blockNumber);
assembly ("memory-safe") {
if proof.length {
let end := add(proof.offset, shl(5, proof.length))
let i := proof.offset
let width := numberOfLeaves

for (uint256 i = 0; i < proof.length; i++) {
bytes32 proofElement = proof[i];

if (position % 2 == 1 || position + 1 == width) {
computedHash = sha256(abi.encodePacked(proofElement, computedHash));
} else {
computedHash = sha256(abi.encodePacked(computedHash, proofElement));
for {} 1 {} {
let leafSlot := shl(5, and(0x1, index))
if eq(add(index, 1), width) {
leafSlot := 0x20
}
mstore(leafSlot, leaf)
mstore(xor(leafSlot, 32), calldataload(i))
leaf := keccak256(0, 64)
index := shr(1, index)
i := add(i, 32)
width := add(shr(1, sub(width, 1)), 1)
if iszero(lt(i, end)) {
break
}
}
}
isMember := eq(leaf, rootHash)

position /= 2;
width = (width - 1) / 2 + 1;
}

return computedHash == getDataRoot(blockNumber);
return isMember;
}
}

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "data-avail"
version = "1.6.0"
version = "1.6.2"
description = "Avail Node"
authors = ["Anonymous"]
homepage = "https://www.availproject.org/"
Expand Down
2 changes: 1 addition & 1 deletion pallets/dactr/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
let rows = BlockLengthRows(prev_power_of_two(rows));
let cols = BlockLengthColumns(cols);

let mut nb_tx = 128; // Value set depending on MaxAppDataLength (16 kb) to reach 2 mb
let mut nb_tx = 4; // Value set depending on MaxAppDataLength (512 kb) to reach 2 mb
let max_tx: u32 =
rows.0 * cols.0 * (BLOCK_CHUNK_SIZE.get().checked_sub(2).unwrap()) / data_length;
if nb_tx > max_tx {
Expand Down
2 changes: 1 addition & 1 deletion pallets/dactr/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl pallet_balances::Config for Test {

parameter_types! {
pub const MaxAppKeyLength: u32 = 32;
pub const MaxAppDataLength: u32 = 16 * 1024; // 16 Kb
pub const MaxAppDataLength: u32 = 512 * 1024; // 512 Kb
pub const MinBlockRows: BlockLengthRows = BlockLengthRows(32);
pub const MaxBlockRows: BlockLengthRows = BlockLengthRows(1024);
pub const MinBlockCols: BlockLengthColumns = BlockLengthColumns(32);
Expand Down
Loading

0 comments on commit c11a4df

Please sign in to comment.