Skip to content

Commit 78494bc

Browse files
authored
Merge pull request #142 from gnosis/force_safe_setup
Don't allow transactions before setting up the Safe
2 parents 0941fef + fbbc712 commit 78494bc

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

contracts/GnosisSafe.sol

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,20 @@ contract GnosisSafe
181181
function checkSignatures(bytes32 dataHash, bytes memory data, bytes memory signatures, bool consumeHash)
182182
internal
183183
{
184+
// Load threshold to avoid multiple storage loads
185+
uint256 _threshold = threshold;
186+
// Check that a threshold is set
187+
require(_threshold > 0, "Threshold needs to be defined!");
184188
// Check that the provided signature data is not too short
185-
require(signatures.length >= threshold.mul(65), "Signatures data too short");
189+
require(signatures.length >= _threshold.mul(65), "Signatures data too short");
186190
// There cannot be an owner with address 0.
187191
address lastOwner = address(0);
188192
address currentOwner;
189193
uint8 v;
190194
bytes32 r;
191195
bytes32 s;
192196
uint256 i;
193-
for (i = 0; i < threshold; i++) {
197+
for (i = 0; i < _threshold; i++) {
194198
(v, r, s) = signatureSplit(signatures, i);
195199
// If v is 0 then it is a contract signature
196200
if (v == 0) {
@@ -200,7 +204,7 @@ contract GnosisSafe
200204
// Check that signature data pointer (s) is not pointing inside the static part of the signatures bytes
201205
// This check is not completely accurate, since it is possible that more signatures than the threshold are send.
202206
// Here we only check that the pointer is not pointing inside the part that is being processed
203-
require(uint256(s) >= threshold.mul(65), "Invalid contract signature location: inside static part");
207+
require(uint256(s) >= _threshold.mul(65), "Invalid contract signature location: inside static part");
204208

205209
// Check that signature data pointer (s) is in bounds (points to the length of data -> 32 bytes)
206210
require(uint256(s).add(32) <= signatures.length, "Invalid contract signature location: length not present");

test/gnosisSafeForceSafeSetup.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const utils = require('./utils/general')
2+
3+
const GnosisSafe = artifacts.require("./GnosisSafe.sol")
4+
5+
contract('GnosisSafe setup', function(accounts) {
6+
7+
let gnosisSafe
8+
let executor = accounts[8]
9+
10+
const CALL = 0
11+
12+
it.only('should not be able to call execTransaction before setup', async () => {
13+
14+
// Create lightwallet
15+
gnosisSafe = await utils.deployContract("deploying Gnosis Safe", GnosisSafe)
16+
17+
// Fund Safe
18+
await web3.eth.sendTransaction({from: accounts[0], to: gnosisSafe.address, value: web3.toWei(1, 'ether')})
19+
assert.equal(await web3.eth.getBalance(gnosisSafe.address).toNumber(), web3.toWei(1, 'ether'))
20+
21+
let sigs = "0x000000000000000000000000" + executor.replace('0x', '') + "0000000000000000000000000000000000000000000000000000000000000000" + "01"
22+
23+
await utils.assertRejects(
24+
gnosisSafe.execTransaction(
25+
accounts[0], web3.toWei(1, 'ether'), "0x", CALL, 0, 0, 0, 0, 0, sigs, {from: executor}
26+
),
27+
"Should not be able to execute transaction before setup"
28+
)
29+
30+
assert.equal(await web3.eth.getBalance(gnosisSafe.address).toNumber(), web3.toWei(1, 'ether'))
31+
32+
let setup = await gnosisSafe.setup([executor], 1, 0, "0x", 0, 0, 0, 0)
33+
utils.logGasUsage("setup", setup)
34+
35+
assert.equal(await web3.eth.getBalance(gnosisSafe.address).toNumber(), web3.toWei(1, 'ether'))
36+
37+
let tx = await gnosisSafe.execTransaction(
38+
executor, web3.toWei(1, 'ether'), "0x", CALL, 0, 0, 0, 0, 0, sigs, {from: executor}
39+
)
40+
utils.logGasUsage("execTransaction after setup", tx)
41+
42+
assert.equal(await web3.eth.getBalance(gnosisSafe.address).toNumber(), web3.toWei(0, 'ether'))
43+
44+
})
45+
})

0 commit comments

Comments
 (0)