Skip to content

Commit

Permalink
Merge pull request #238 from makerdao/add_generateSig_script
Browse files Browse the repository at this point in the history
Freeze dai déployment addresse
  • Loading branch information
julienmartinlevrai authored Nov 15, 2021
2 parents eacdaa4 + 3c4501d commit c666ab1
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/out
.DS_Store
scripts/node_modules
scripts/package-lock.json
scripts/package.json
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

build :; DAPP_BUILD_OPTIMIZE=0 DAPP_BUILD_OPTIMIZE_RUNS=0 dapp --use solc:0.6.12 build
clean :; dapp clean
test :; DAPP_BUILD_OPTIMIZE=0 DAPP_BUILD_OPTIMIZE_RUNS=0 dapp --use solc:0.6.12 test -v ${TEST_FLAGS}
test :; DAPP_BUILD_OPTIMIZE=0 DAPP_BUILD_OPTIMIZE_RUNS=0 DAPP_TEST_ADDRESS=0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B dapp --use solc:0.6.12 test -v ${TEST_FLAGS}
test-gas : build
LANG=C.UTF-8 hevm dapp-test --rpc="${ETH_RPC_URL}" --json-file=out/dapp.sol.json --dapp-root=. --verbose 2 --match "test_gas"
61 changes: 61 additions & 0 deletions scripts/generateSig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const ethUtil = require('ethereumjs-util');
const sigUtil = require('eth-sig-util');
const utils = sigUtil.TypedDataUtils;

//Our lad Cal wants to send 2 dai to del, by signing a cheque and paying a 1 dai fee to msg.sender

const calprivKeyHex = '4af1bceebf7f3634ec3cff8a2c38e51178d5d4ce585c52d6043e5e2cc3418bb0'
const calprivKey = new Buffer.from(calprivKeyHex, 'hex')
const cal = ethUtil.privateToAddress(calprivKey);
const del = new Buffer.from('dd2d5d3f7f1b35b7a0601d6a00dbb7d44af58479', 'hex');
const dai = new Buffer.from('11Ee1eeF5D446D07Cf26941C7F2B4B1Dfb9D030B', 'hex');
console.log('cals address: ' + '0x' + cal.toString('hex'));
console.log('dels address: ' + '0x' + del.toString('hex'));
let typedData = {
types: {
EIP712Domain: [
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
],
Permit: [
{ name: 'holder', type: 'address' },
{ name: 'spender', type: 'address' },
{ name: 'nonce', type: 'uint256' },
{ name: 'expiry', type: 'uint256' },
{ name: 'allowed', type: 'bool' },
],
},
primaryType: 'Permit',
domain: {
name: 'Dai Stablecoin',
version: '1',
chainId: 99,
verifyingContract: '0x11Ee1eeF5D446D07Cf26941C7F2B4B1Dfb9D030B', //in hevm
},
message: {
holder: '0x'+cal.toString('hex'),
spender: '0x'+del.toString('hex'),
nonce: 0,
expiry: 604411200 + 3600,
allowed: true
},
};

let hash = ethUtil.bufferToHex(utils.hashStruct('EIP712Domain', typedData.domain, typedData.types))
console.log('EIP712DomainHash: ' + hash);
hash = ethUtil.bufferToHex(utils.hashType('Permit', typedData.types))
console.log('Permit Typehash: ' + hash);
hash = ethUtil.bufferToHex(utils.hashStruct('Permit', typedData.message, typedData.types))
console.log('Permit (from cal to del) hash: ' + hash);
const sig = sigUtil.signTypedData(calprivKey, { data: typedData });
console.log('signed permit: ' + sig);

let r = sig.slice(0,66);
let s = '0x'+ sig.slice(66,130);
let v = ethUtil.bufferToInt(ethUtil.toBuffer('0x'+sig.slice(130,132),'hex'));

console.log('r: ' + r)
console.log('s: ' + s)
console.log('v: ' + v)
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

mkShell {
DAPP_SOLC = solc-static-versions.solc_0_6_12 + "/bin/solc-0.6.12";
DAPP_TEST_ADDRESS = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B";
# No optimizations
SOLC_FLAGS = "";
buildInputs = [
Expand Down
14 changes: 7 additions & 7 deletions src/test/dai.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ contract DaiTest is DSTest {
uint deadline = 0;
address cal = 0x29C76e6aD8f28BB1004902578Fb108c507Be341b;
address del = 0xdd2d5D3f7f1b35b7A0601D6A00DbB7D44Af58479;
bytes32 r = 0x46323dda87c592902a10f931e64a8160ae899d141f46b07a73e676b0e5daa1c4;
bytes32 s = 0x6339a2fc9fdf1c0737fb35eb0928f0558170e3900da9b483ed1904bd9fdb2f87;
uint8 v = 28;
bytes32 _r = 0x8c37dc98d15d1f9907c731184d4aaad7896d5d9424c8a5c002bc569b3bf50ba6;
bytes32 _s = 0x0a561c49460341843d248c63923be1d7c67bc2b5753bd07835be47828e4d0c2e;
bytes32 r = 0x8e30095d9e5439a4f4b8e4b5c94e7639756474d72aded20611464c8f002efb06;
bytes32 s = 0x49a0ed09658bc768d6548689bcbaa430cefa57846ef83cb685673a9b9a575ff4;
uint8 v = 27;
bytes32 _r = 0x85da10f8af2cf512620c07d800f8e17a2a4cd2e91bf0835a34bf470abc6b66e5;
bytes32 _s = 0x7e8e641e5e8bef932c3a55e7365e0201196fc6385d942c47d749bf76e73ee46f;
uint8 _v = 27;


Expand Down Expand Up @@ -279,15 +279,15 @@ contract DaiTest is DSTest {
function testDaiAddress() public {
//The dai address generated by hevm
//used for signature generation testing
assertEq(address(token), address(0xDB356e865AAaFa1e37764121EA9e801Af13eEb83));
assertEq(address(token), address(0x11Ee1eeF5D446D07Cf26941C7F2B4B1Dfb9D030B));
}

function testTypehash() public {
assertEq(token.PERMIT_TYPEHASH(), 0xea2aa0a1be11a07ed86d755c93467f4f82362b452371d1ba94d1715123511acb);
}

function testDomain_Separator() public {
assertEq(token.DOMAIN_SEPARATOR(), 0x92a148ae95a9faf19ab88b195b0da85dd00a6764ac8a66d5e64fb3add1579cac);
assertEq(token.DOMAIN_SEPARATOR(), 0x68a9504c1a7fba795f7730732abab11cb5fa5113edd2396392abd5c1bbda4043);
}

function testPermit() public {
Expand Down

0 comments on commit c666ab1

Please sign in to comment.