Would have been much easier with an ethereum smart contract. No gimmicky address list, it's a crowdsourced picture in the blockchain.
contract Place {
struct Pixel {
bytes3 color;
uint lastPayment;
}
Pixel[10000][10000] board;
modifier onBoard(uint x, uint y) {
if (x > 10000 || y > 10000) {
throw;
}
_;
}
// Accepts funds, if the funds sent are greater than funds for that pixel last, change the color.
function colorPixel(uint x, uint y, bytes3 color) payable onBoard(x, y) {
Pixel p = board[x][y];
if (msg.value > p.lastPayment) {
msg.sender.send(p.lastPayment); // refund previous price of pixel
p.color = color; // set the color
p.lastPayment = msg.value; // set new cost to whatever the person sent in
} else {
throw;
}
}
}
May contain an error or two, but that's the general gist of it.
> msg.sender.send(p.lastPayment); // refund previous price of pixel
This code suffers from Recursive calling vulnerability (same bug which caused the DAO to be hacked).
You're sending the money BEFORE you're updating the balances.
There is a better way to write the payment code (and also wouldn't take you more than 5 minutes to write).
Here is one way to do it:
function colorPixel(uint x, uint y, bytes3 color) payable onBoard(x, y) {
Pixel p = board[x][y];
lastPayment = p.lastPayment;
p.lastPayment = msg.value;
if (msg.value > lastPayment) {
if(!msg.sender.send(lastPayment)) throw; // refund previous price of pixel
p.color = color; // set the color
} else {
throw;
}
}
Another shorter way:
function colorPixel(uint x, uint y, bytes3 color) payable onBoard(x, y) {
Pixel p = board[x][y];
require(msg.value > p.lastPayment);
if(!msg.sender.send(p.lastPayment)) throw; // refund previous price of pixel
p.color = color; // set the color
p.lastPayment = msg.value; // set new cost to whatever the person sent in
}
IUUC the current code accumulate the payment to each pixel and whatever color has more accumulated money is chosen.
IIUC your code only consider the last payment and to replace the old color you have to outbid it, without any consideration of the previous payments.
Another strategies:
Penny auction: Whatever color received the last payment is the chosen one. This is more similar to /r/place
Generals.io: If someone adds money to the current color, then increase the accumulated money in that color. If someone adds money to another color the amount is discounted. Unless the result is negative and the color changes.
Yea, with a 0.001 BTC (~$1.42) minimum, this 100x100 pixel pilot could generate $14,200 if all pixels are colored and no pixels are contested. If it scales, in both pixels and interest, a decent amount of donations could be generated.
That said, cryptocurrency is much more niche than, say, an open-access canvas requiring only a Reddit account.
It'd be fun to make a free version using the same concept by rolling your own proof of work system. You could do something like requiring a unique proof of work to be submitted for each pixel change. To change a pixel you need to generate a random number which hashes to a lower value (when interpreted as a bignum) than the existing holder of the pixel.
The UI for something like that would be great - your client could just constantly generate random hashes and buffer a list of the best values its has come up with. Then the screen could highlight all pixels you can edit. As you wait longer (and generate better and better hashes), you can edit more 'valuable' pixels.
(Of course, that would only work if each hash could only be used once. You could embed the pixel value into the hash's input, but then you'd need to decide which pixels you want to edit before you start generating hashes. And that would be way less fun.)
It's not obvious enough how to see the image. It's linked from the image at the top and there is a link at the bottom, but you should add something more obvious like "look at the current image!!!"
Also, it would be nice that the image at the top is live, something like a gif autogenerated once a minute.
[+] [-] scientaster|8 years ago|reply
[+] [-] splintercell|8 years ago|reply
This code suffers from Recursive calling vulnerability (same bug which caused the DAO to be hacked).
You're sending the money BEFORE you're updating the balances.
There is a better way to write the payment code (and also wouldn't take you more than 5 minutes to write).
Here is one way to do it:
Another shorter way:[+] [-] gus_massa|8 years ago|reply
IUUC the current code accumulate the payment to each pixel and whatever color has more accumulated money is chosen.
IIUC your code only consider the last payment and to replace the old color you have to outbid it, without any consideration of the previous payments.
Another strategies:
Penny auction: Whatever color received the last payment is the chosen one. This is more similar to /r/place
Generals.io: If someone adds money to the current color, then increase the accumulated money in that color. If someone adds money to another color the amount is discounted. Unless the result is negative and the color changes.
[+] [-] mess110|8 years ago|reply
[+] [-] pavel_lishin|8 years ago|reply
[+] [-] iplaw|8 years ago|reply
That said, cryptocurrency is much more niche than, say, an open-access canvas requiring only a Reddit account.
[+] [-] i_cant_speel|8 years ago|reply
[+] [-] josephg|8 years ago|reply
The UI for something like that would be great - your client could just constantly generate random hashes and buffer a list of the best values its has come up with. Then the screen could highlight all pixels you can edit. As you wait longer (and generate better and better hashes), you can edit more 'valuable' pixels.
(Of course, that would only work if each hash could only be used once. You could embed the pixel value into the hash's input, but then you'd need to decide which pixels you want to edit before you start generating hashes. And that would be way less fun.)
[+] [-] gus_massa|8 years ago|reply
Also, it would be nice that the image at the top is live, something like a gif autogenerated once a minute.
[+] [-] libeclipse|8 years ago|reply
Also, how would you protect against faked transactions? Certainly waiting for confirmations is out of the question.
[+] [-] mess110|8 years ago|reply
This is not as dynamic as Reddit Place, the code is waiting for 1 confirmation before the pixel is colored.
[+] [-] root_axis|8 years ago|reply
[+] [-] iplaw|8 years ago|reply
[+] [-] marinel|8 years ago|reply
[deleted]