Skip to content

Commit

Permalink
Add name sigs (#60)
Browse files Browse the repository at this point in the history
* add name to delegate sig

* adding token name to vote

* bump version
  • Loading branch information
brossetti1 authored Aug 24, 2022
1 parent 1b85501 commit 54a1dbf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
12 changes: 10 additions & 2 deletions contracts/Baal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ contract Baal is Module, EIP712 {
address public multisendLibrary; /*address of multisend library*/

// SIGNATURE HELPERS
bytes32 constant VOTE_TYPEHASH = keccak256("Vote(address voter,uint32 proposalId,bool support)");
bytes32 constant VOTE_TYPEHASH = keccak256("Vote(string name,address voter,uint32 proposalId,bool support)");

// DATA STRUCTURES
struct Proposal {
Expand Down Expand Up @@ -431,7 +431,15 @@ contract Baal is Module, EIP712 {
bytes32 s
) external nonReentrant {
/*calculate EIP-712 struct hash*/
bytes32 structHash = keccak256(abi.encode(VOTE_TYPEHASH, voter, id, approved));
bytes32 structHash = keccak256(
abi.encode(
VOTE_TYPEHASH,
keccak256(abi.encodePacked(sharesToken.name())),
voter,
id,
approved
)
);
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);

Expand Down
11 changes: 8 additions & 3 deletions contracts/utils/BaalVotes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ abstract contract BaalVotes is ERC20Permit {
mapping(address => address) public delegates; /*maps record of each account's `shares` delegate*/

// SIGNATURE HELPERS
bytes32 constant DELEGATION_TYPEHASH =
keccak256("Delegation(address delegatee,uint256 nonce,uint256 expiry)");
bytes32 constant DELEGATION_TYPEHASH = keccak256("Delegation(string name,address delegatee,uint256 nonce,uint256 expiry)");

event DelegateChanged(
address indexed delegator,
Expand Down Expand Up @@ -82,7 +81,13 @@ abstract contract BaalVotes is ERC20Permit {
address signer = ECDSA.recover(
_hashTypedDataV4(
keccak256(
abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry)
abi.encode(
DELEGATION_TYPEHASH,
keccak256(abi.encodePacked(name())),
delegatee,
nonce,
expiry
)
)
),
v,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daohaus/baal-contracts",
"version": "0.3.4",
"version": "0.3.5",
"description": "Lo, also it is the time of His rain.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
10 changes: 7 additions & 3 deletions src/signDelegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ export default async function signDelegation(
expiry: number
) {
const domain = {
name,
name: 'Shares',
version: '1',
chainId,
verifyingContract: contractAddress,
}

const types = {
Delegation: [
{ name: 'name', type: 'string' },
{ name: 'delegatee', type: 'address' },
{ name: 'nonce', type: 'uint256' },
{ name: 'expiry', type: 'uint256' },
],
}

const sig = await signer._signTypedData(domain, types, {
const values = {
name,
delegatee,
nonce,
expiry,
})
}

const sig = await signer._signTypedData(domain, types, values)

return sig
}
10 changes: 7 additions & 3 deletions src/signVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ export default async function signVote(

) {
const domain = {
name,
name: 'Vote',
version: '4',
chainId,
verifyingContract: contractAddress,
}

const types = {
Vote: [
{ name: 'name', type: 'string' },
{ name: 'voter', type: 'address' },
{ name: 'proposalId', type: 'uint32' },
{ name: 'support', type: 'bool' },
],
}

const sig = await signer._signTypedData(domain, types, {
const values = {
name,
voter: signer.address,
proposalId,
support
})
}

const sig = await signer._signTypedData(domain, types, values)

return sig
}
12 changes: 6 additions & 6 deletions test/BaalSafe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ describe("Baal contract", function () {
chainId,
baal.address,
summoner,
"Vote", // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
1,
true
);
Expand All @@ -2356,7 +2356,7 @@ describe("Baal contract", function () {
chainId,
baal.address,
summoner,
"Vote", // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
1,
true
);
Expand All @@ -2372,7 +2372,7 @@ describe("Baal contract", function () {
chainId,
baal.address,
summoner,
"Vote", // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
1,
true
);
Expand Down Expand Up @@ -2402,7 +2402,7 @@ describe("Baal contract", function () {
chainId,
sharesToken.address,
summoner,
'Shares', // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
shaman.address,
nonce,
expiry
Expand All @@ -2421,7 +2421,7 @@ describe("Baal contract", function () {
chainId,
sharesToken.address,
summoner,
'Shares', // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
shaman.address,
nonce,
expiry
Expand All @@ -2440,7 +2440,7 @@ describe("Baal contract", function () {
chainId,
sharesToken.address,
summoner,
'Shares', // deploymentConfig.TOKEN_NAME
deploymentConfig.TOKEN_NAME,
shaman.address,
nonce,
0
Expand Down

0 comments on commit 54a1dbf

Please sign in to comment.