Skip to content

Commit

Permalink
fix(contract): convert to acl (#25)
Browse files Browse the repository at this point in the history
* fix(contract): make implementation only an ACL

* chore: bindings
  • Loading branch information
rymnc authored Aug 2, 2024
1 parent f819a58 commit d473de2
Show file tree
Hide file tree
Showing 18 changed files with 630 additions and 1,287 deletions.
8 changes: 2 additions & 6 deletions contracts/src/IScKeystore.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

struct UserInfo {
bytes signaturePubKey;
}

interface IScKeystore {
function userExists(address user) external view returns (bool);

function addUser(address user, bytes calldata signaturePubKey) external;
function addUser(address user) external;

function getUser(address user) external view returns (UserInfo memory);
function removeUser(address user) external;
}
23 changes: 12 additions & 11 deletions contracts/src/ScKeystore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,34 @@
pragma solidity 0.8.24;

import { Ownable } from "Openzeppelin/access/Ownable.sol";
import { IScKeystore, UserInfo } from "./IScKeystore.sol";
import { IScKeystore } from "./IScKeystore.sol";

error UserAlreadyExists();
error MalformedUserInfo();
error UserDoesNotExist();

contract ScKeystore is Ownable, IScKeystore {
event UserAdded(address user, bytes signaturePubKey);
event UserAdded(address user);
event UserRemoved(address user);

mapping(address user => UserInfo userInfo) private users;
mapping(address user => bool exists) private users;

constructor(address initialOwner) Ownable(initialOwner) { }

function userExists(address user) public view returns (bool) {
return users[user].signaturePubKey.length > 0;
return users[user];
}

function addUser(address user, bytes calldata signaturePubKey) external onlyOwner {
if (signaturePubKey.length == 0) revert MalformedUserInfo();
function addUser(address user) external onlyOwner {
if (userExists(user)) revert UserAlreadyExists();

users[user] = UserInfo(signaturePubKey);
users[user] = true;

emit UserAdded(user, signaturePubKey);
emit UserAdded(user);
}

function getUser(address user) external view returns (UserInfo memory) {
return users[user];
function removeUser(address user) external onlyOwner {
if (!userExists(user)) revert UserDoesNotExist();
users[user] == false;
emit UserRemoved(user);
}
}
17 changes: 8 additions & 9 deletions contracts/test/ScKeystore.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract ScKeystoreTest is Test {
}

function addUser() internal {
s.addUser(address(this), "0x");
s.addUser(address(this));
}

function test__owner() public view {
Expand All @@ -29,11 +29,6 @@ contract ScKeystoreTest is Test {
assert(!s.userExists(address(this)));
}

function test__addUser__reverts__whenUserInfoIsMalformed() public {
vm.expectRevert(MalformedUserInfo.selector);
s.addUser(address(this), "");
}

function test__addUser__reverts__whenUserAlreadyExists() public {
addUser();
vm.expectRevert(UserAlreadyExists.selector);
Expand All @@ -52,9 +47,13 @@ contract ScKeystoreTest is Test {
vm.stopPrank();
}

function test__getUser__returnsUserInfo__whenUserExists() public {
function test__removeUser__reverts__whenUserDoesNotExist() public {
vm.expectRevert();
s.removeUser(address(0));
}

function test__removeUser() public {
addUser();
UserInfo memory userInfo = s.getUser(address(this));
assert(userInfo.signaturePubKey.length == 2);
s.removeUser(address(this));
}
}
2 changes: 0 additions & 2 deletions crates/bindings/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod Context {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand All @@ -29,7 +28,6 @@ pub mod Context {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand Down
10 changes: 4 additions & 6 deletions crates/bindings/src/deploy.rs

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions crates/bindings/src/deploymentconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ pub mod DeploymentConfig {
///0x6080604052600c805462ff00ff19166201000117905534801561002157600080fd5b50604051610223380380610223833981016040819052610040916100f0565b6001600160a01b0381166100675760405163201616d160e21b815260040160405180910390fd5b600e80546001600160a01b0319166001600160a01b03831617905546617a69036100cb57604080516020808201835260009091528151908101909152600e546001600160a01b031690819052600d80546001600160a01b03191690911790556100ea565b604051630b13dbff60e01b815246600482015260240160405180910390fd5b50610120565b60006020828403121561010257600080fd5b81516001600160a01b038116811461011957600080fd5b9392505050565b60f58061012e6000396000f3fe6080604052348015600f57600080fd5b506004361060465760003560e01c806312900da814604b578063d7b6574514608f578063f8a8fd6d1460d2578063f8ccbf471460d4575b600080fd5b6040805160208082018352600090915281518082018352600e5473ffffffffffffffffffffffffffffffffffffffff16908190529151918252015b60405180910390f35b600d5460ae9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016086565b005b600c5460e69062010000900460ff1681565b6040519015158152602001608656
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"`\x80`@R`\x0C\x80Tb\xFF\0\xFF\x19\x16b\x01\0\x01\x17\x90U4\x80\x15a\0!W`\0\x80\xFD[P`@Qa\x02#8\x03\x80a\x02#\x839\x81\x01`@\x81\x90Ra\0@\x91a\0\xF0V[`\x01`\x01`\xA0\x1B\x03\x81\x16a\0gW`@Qc \x16\x16\xD1`\xE2\x1B\x81R`\x04\x01`@Q\x80\x91\x03\x90\xFD[`\x0E\x80T`\x01`\x01`\xA0\x1B\x03\x19\x16`\x01`\x01`\xA0\x1B\x03\x83\x16\x17\x90UFazi\x03a\0\xCBW`@\x80Q` \x80\x82\x01\x83R`\0\x90\x91R\x81Q\x90\x81\x01\x90\x91R`\x0ET`\x01`\x01`\xA0\x1B\x03\x16\x90\x81\x90R`\r\x80T`\x01`\x01`\xA0\x1B\x03\x19\x16\x90\x91\x17\x90Ua\0\xEAV[`@Qc\x0B\x13\xDB\xFF`\xE0\x1B\x81RF`\x04\x82\x01R`$\x01`@Q\x80\x91\x03\x90\xFD[Pa\x01 V[`\0` \x82\x84\x03\x12\x15a\x01\x02W`\0\x80\xFD[\x81Q`\x01`\x01`\xA0\x1B\x03\x81\x16\x81\x14a\x01\x19W`\0\x80\xFD[\x93\x92PPPV[`\xF5\x80a\x01.`\09`\0\xF3\xFE`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`\x046\x10`FW`\x005`\xE0\x1C\x80c\x12\x90\r\xA8\x14`KW\x80c\xD7\xB6WE\x14`\x8FW\x80c\xF8\xA8\xFDm\x14`\xD2W\x80c\xF8\xCC\xBFG\x14`\xD4W[`\0\x80\xFD[`@\x80Q` \x80\x82\x01\x83R`\0\x90\x91R\x81Q\x80\x82\x01\x83R`\x0ETs\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x16\x90\x81\x90R\x91Q\x91\x82R\x01[`@Q\x80\x91\x03\x90\xF3[`\rT`\xAE\x90s\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x16\x81V[`@Qs\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x90\x91\x16\x81R` \x01`\x86V[\0[`\x0CT`\xE6\x90b\x01\0\0\x90\x04`\xFF\x16\x81V[`@Q\x90\x15\x15\x81R` \x01`\x86V",
);
Expand All @@ -124,7 +123,6 @@ pub mod DeploymentConfig {
///0x6080604052348015600f57600080fd5b506004361060465760003560e01c806312900da814604b578063d7b6574514608f578063f8a8fd6d1460d2578063f8ccbf471460d4575b600080fd5b6040805160208082018352600090915281518082018352600e5473ffffffffffffffffffffffffffffffffffffffff16908190529151918252015b60405180910390f35b600d5460ae9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016086565b005b600c5460e69062010000900460ff1681565b6040519015158152602001608656
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`\x046\x10`FW`\x005`\xE0\x1C\x80c\x12\x90\r\xA8\x14`KW\x80c\xD7\xB6WE\x14`\x8FW\x80c\xF8\xA8\xFDm\x14`\xD2W\x80c\xF8\xCC\xBFG\x14`\xD4W[`\0\x80\xFD[`@\x80Q` \x80\x82\x01\x83R`\0\x90\x91R\x81Q\x80\x82\x01\x83R`\x0ETs\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x16\x90\x81\x90R\x91Q\x91\x82R\x01[`@Q\x80\x91\x03\x90\xF3[`\rT`\xAE\x90s\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x16\x81V[`@Qs\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x90\x91\x16\x81R` \x01`\x86V[\0[`\x0CT`\xE6\x90b\x01\0\0\x90\x04`\xFF\x16\x81V[`@Q\x90\x15\x15\x81R` \x01`\x86V",
);
Expand Down Expand Up @@ -184,9 +182,6 @@ struct NetworkConfig { address deployer; }
}
#[inline]
fn stv_abi_encoded_size(&self) -> usize {
if let Some(size) = <Self as alloy_sol_types::SolType>::ENCODED_SIZE {
return size;
}
let tuple = <UnderlyingRustTuple<
'_,
> as ::core::convert::From<Self>>::from(self.clone());
Expand All @@ -210,18 +205,6 @@ struct NetworkConfig { address deployer; }
'_,
> as alloy_sol_types::SolType>::abi_encode_packed_to(&tuple, out)
}
#[inline]
fn stv_abi_packed_encoded_size(&self) -> usize {
if let Some(size) = <Self as alloy_sol_types::SolType>::PACKED_ENCODED_SIZE {
return size;
}
let tuple = <UnderlyingRustTuple<
'_,
> as ::core::convert::From<Self>>::from(self.clone());
<UnderlyingSolTuple<
'_,
> as alloy_sol_types::SolType>::abi_packed_encoded_size(&tuple)
}
}
#[automatically_derived]
impl alloy_sol_types::SolType for NetworkConfig {
Expand All @@ -233,9 +216,6 @@ struct NetworkConfig { address deployer; }
const ENCODED_SIZE: Option<usize> = <UnderlyingSolTuple<
'_,
> as alloy_sol_types::SolType>::ENCODED_SIZE;
const PACKED_ENCODED_SIZE: Option<usize> = <UnderlyingSolTuple<
'_,
> as alloy_sol_types::SolType>::PACKED_ENCODED_SIZE;
#[inline]
fn valid_token(token: &Self::Token<'_>) -> bool {
<UnderlyingSolTuple<'_> as alloy_sol_types::SolType>::valid_token(token)
Expand Down
2 changes: 0 additions & 2 deletions crates/bindings/src/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub mod Foo {
///0x6080604052348015600f57600080fd5b5060658061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80637d3c40c814602d575b600080fd5b603b6038366004604d565b90565b60405190815260200160405180910390f35b600060208284031215605e57600080fd5b503591905056
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`e\x80a\0\x1E`\09`\0\xF3\xFE`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`\x046\x10`(W`\x005`\xE0\x1C\x80c}<@\xC8\x14`-W[`\0\x80\xFD[`;`86`\x04`MV[\x90V[`@Q\x90\x81R` \x01`@Q\x80\x91\x03\x90\xF3[`\0` \x82\x84\x03\x12\x15`^W`\0\x80\xFD[P5\x91\x90PV",
);
Expand All @@ -51,7 +50,6 @@ pub mod Foo {
///0x6080604052348015600f57600080fd5b506004361060285760003560e01c80637d3c40c814602d575b600080fd5b603b6038366004604d565b90565b60405190815260200160405180910390f35b600060208284031215605e57600080fd5b503591905056
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"`\x80`@R4\x80\x15`\x0FW`\0\x80\xFD[P`\x046\x10`(W`\x005`\xE0\x1C\x80c}<@\xC8\x14`-W[`\0\x80\xFD[`;`86`\x04`MV[\x90V[`@Q\x90\x81R` \x01`@Q\x80\x91\x03\x90\xF3[`\0` \x82\x84\x03\x12\x15`^W`\0\x80\xFD[P5\x91\x90PV",
);
Expand Down
2 changes: 0 additions & 2 deletions crates/bindings/src/ierc165.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ pub mod IERC165 {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand All @@ -51,7 +50,6 @@ pub mod IERC165 {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand Down
59 changes: 12 additions & 47 deletions crates/bindings/src/ierc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ pub mod IERC20 {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand All @@ -265,7 +264,6 @@ pub mod IERC20 {
///0x
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
pub static DEPLOYED_BYTECODE: alloy_sol_types::private::Bytes = alloy_sol_types::private::Bytes::from_static(
b"",
);
Expand Down Expand Up @@ -377,20 +375,15 @@ event Approval(address indexed owner, address indexed spender, uint256 value);
Ok(())
}
}
#[automatically_derived]
impl alloy_sol_types::private::IntoLogData for Approval {
fn to_log_data(&self) -> alloy_sol_types::private::LogData {
From::from(self)
}
fn into_log_data(self) -> alloy_sol_types::private::LogData {
From::from(&self)
}
}
#[automatically_derived]
impl From<&Approval> for alloy_sol_types::private::LogData {
#[inline]
fn from(this: &Approval) -> alloy_sol_types::private::LogData {
alloy_sol_types::SolEvent::encode_log_data(this)
let topics = alloy_sol_types::SolEvent::encode_topics(this)
.into_iter()
.map(|t| t.into())
.collect();
let data = alloy_sol_types::SolEvent::encode_data(this).into();
alloy_sol_types::private::LogData::new_unchecked(topics, data)
}
}
};
Expand Down Expand Up @@ -502,20 +495,15 @@ event Transfer(address indexed from, address indexed to, uint256 value);
Ok(())
}
}
#[automatically_derived]
impl alloy_sol_types::private::IntoLogData for Transfer {
fn to_log_data(&self) -> alloy_sol_types::private::LogData {
From::from(self)
}
fn into_log_data(self) -> alloy_sol_types::private::LogData {
From::from(&self)
}
}
#[automatically_derived]
impl From<&Transfer> for alloy_sol_types::private::LogData {
#[inline]
fn from(this: &Transfer) -> alloy_sol_types::private::LogData {
alloy_sol_types::SolEvent::encode_log_data(this)
let topics = alloy_sol_types::SolEvent::encode_topics(this)
.into_iter()
.map(|t| t.into())
.collect();
let data = alloy_sol_types::SolEvent::encode_data(this).into();
alloy_sol_types::private::LogData::new_unchecked(topics, data)
}
}
};
Expand Down Expand Up @@ -2055,29 +2043,6 @@ function transferFrom(address from, address to, uint256 amount) external returns
}
}
}
#[automatically_derived]
impl alloy_sol_types::private::IntoLogData for IERC20Events {
fn to_log_data(&self) -> alloy_sol_types::private::LogData {
match self {
Self::Approval(inner) => {
alloy_sol_types::private::IntoLogData::to_log_data(inner)
}
Self::Transfer(inner) => {
alloy_sol_types::private::IntoLogData::to_log_data(inner)
}
}
}
fn into_log_data(self) -> alloy_sol_types::private::LogData {
match self {
Self::Approval(inner) => {
alloy_sol_types::private::IntoLogData::into_log_data(inner)
}
Self::Transfer(inner) => {
alloy_sol_types::private::IntoLogData::into_log_data(inner)
}
}
}
}
use alloy::contract as alloy_contract;
/**Creates a new wrapper around an on-chain [`IERC20`](self) contract instance.
Expand Down
Loading

0 comments on commit d473de2

Please sign in to comment.