Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
feat: Add access control to measure + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
AmeanAsad committed Aug 5, 2023
1 parent f689ecc commit b7fca33
Show file tree
Hide file tree
Showing 8 changed files with 1,174 additions and 72 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,25 @@ This deployment method requires manual insertion of a private key and is not rec
NOTE: Deployment using forge CLI often errors out on Filecoin networks even though the transaction goes through (Foundry
is configured for EVM's block time, not FVM's). Use a block explorer to find the address of the contract.

Make sure the following env vars are defined as follows:
```bash
forge create --rpc-url https://api.calibration.node.glif.io/rpc/v1 --private-key <your_private_key> src/Measure.sol:Measure
export RPC_URL="..."
export ADMIN_ADDRESS="..."
export MNEMONIC_PATH="{path to mnemonic secret file}"
```

To deploy using a private key, run:

```bash
forge create --rpc-url $RPC_URL --private-key <your_private_key> src/Measure.sol:Measure --constructor-args $ADMIN_ADDRESS
```

To deploy using a local mnemonic secret, run:
```bash
forge create --rpc-url $RPC_URL --mnemonic $MNEMONIC_PATH src/Measure.sol:Measure --constructor-args $ADMIN_ADDRESS
```


### Deployment Rust Script

The deployment relies on contract bindings generated in the `/contract-bindings` directory. If you make changes to the contracts, run:
Expand Down
1,183 changes: 1,125 additions & 58 deletions contract-bindings/src/measure.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion contract-utils/openzeppelin-contracts
Submodule openzeppelin-contracts deleted from 54a235
3 changes: 2 additions & 1 deletion contract-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ pub mod measure {
client: Arc<S>,
retries: usize,
provider: Provider<Http>,
address: H160,
) -> Result<H160, Box<dyn std::error::Error>> {
let gas_price = provider.get_gas_price().await?;
println!("current gas price: {:#?}", gas_price);
println!("using {} retries", retries);

let mut contract = Measure::deploy(client.clone(), ())?;
let mut contract = Measure::deploy(client.clone(), address)?;
let tx = contract.deployer.tx.clone();
set_tx_gas(
&mut contract.deployer.tx,
Expand Down
4 changes: 2 additions & 2 deletions contract-utils/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn main() {
.await
.unwrap();
let client = Arc::new(ledger_client);
deploy_factory_contract(client.clone(), RETRIES, provider)
deploy_factory_contract(client.clone(), RETRIES, provider, client.address())
.await
.unwrap();
}
Expand All @@ -32,7 +32,7 @@ async fn main() {
.await
.unwrap();
let client = Arc::new(local_client);
deploy_factory_contract(client.clone(), RETRIES, provider)
deploy_factory_contract(client.clone(), RETRIES, provider, client.address())
.await
.unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion contract-utils/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async fn deploy() -> Result<(), Box<dyn std::error::Error>> {
.await
.unwrap();
let client = Arc::new(local_client);
let address = deploy_factory_contract(client.clone(), 15, provider)
let address = deploy_factory_contract(client.clone(), 15, provider, client.address())
.await
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ src = 'src'
out = 'out'
libs = ['lib']
fs_permissions = [{ access = "read", path = "./"}]
solc-version = "0.8.17"
solc-version = "0.8.21"
optimizer = true
optimizer-runs = 10_000_000

[rpc_endpoints]
hyperspace = "${HYPERSPACE_RPC_URL}"
calibration = "https://api.calibration.node.glif.io/rpc/v1"
32 changes: 26 additions & 6 deletions src/Measure.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
// SPDX-License-Identifier: (MIT or Apache-2.0)

pragma solidity ^0.8.17;
import "../lib/openzeppelin-contracts/contracts/access/AccessControl.sol";
pragma solidity ^0.8.19;

contract Measure {
event Measurement(string data);
/**
* @title Measure Contract
* @dev This contract submits commitments of arbitrary data on chain.
*/
contract Measure is AccessControl {
event Measurement(string dataCommitment);
bytes32 public constant COMMITMENT_ROLE = keccak256("COMMITMENT_ROLE");

function measure(string memory data) public {
emit Measurement(data);
}
/**
* @dev Creates a measure contract with an admin
* @param admin The address of the factory admin.
**/
constructor(address admin) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(COMMITMENT_ROLE, admin);
}

/**
* @dev Emmits a Measurement event with a commitment to some arbitrary data.
* @param dataCommitment An arbitrary commitment to some data (eg. Merkle Root, KZG Commitment, etc.)
**/
function measure(string memory dataCommitment) public {
require(hasRole(COMMITMENT_ROLE, msg.sender));
emit Measurement(dataCommitment);
}
}

0 comments on commit b7fca33

Please sign in to comment.