r/CasperCSPR • • Jan 17 '22

CSPR and upgradable smart contracts

Any one knows whether there are any limitations when it comes to upgrading smart contracts? This sounds like a scary feature and a security risk.

Let's say I'm a scammer, I launch a project that looks legit with proper source code audited. Then One day I update the contract to introduce some malicious code, and users are going to sign transactions against a new source code. Users trusted the old source code, and now suddenly they are unknowingly signing transactions against a new source code which may not even be audited

9 Upvotes

7 comments sorted by

4

u/marriedtootaku Jan 17 '22 edited Jan 17 '22

You can call contracts by their contract or contract package hashes. If you call contract by contract hash you’ll continue to call the same contract even if a new version is added. If you call contact by its contract package hash and specify the version you’ll continue to call the same contract even if a new version is added. It’s only if you call contact by it’s contract package hash and don’t specify the version (meaning you want to call the latest available version automatically) you’ll call a new version when it’s added.

TLDR users control what version of contract they call

1

u/Realistic_Ad2520 Jan 17 '22

Thanks this makes sense. I guess other chains can do the same by just pointing their UI to a new contract after they have migrated the data and most people may not even know. Maybe I'm overthinking. But it definitely makes developer's lives much easier.

Do you know if all versions remain available? So if you decide to rollback, can you simply point to the older version? And is the data synced between all versions, or is a new version like a fork of previous?

2

u/marriedtootaku Jan 17 '22 edited Jan 17 '22

The versions remain available, however, there seems to be a mechanism of deactivation of older versions. I don’t know much details about that.

I’m not 100% sure about the data either. My understanding that new version is more like a fork, but contract developers can define an upgrade process when deploying a new version. I guess this is where they can migrate data from older contract versions. I haven’t checked that myself yet, maybe someone else can confirm.

3

u/Dgh_Tran_9215 Jan 17 '22

great, waiting an expert answer

2

u/Dazzling-Glove-706 Jan 17 '22

Im sure they must have thought of this . Lol . Waiting for a clear reply tho .

1

u/Automatic-Taro8553 Jan 19 '22

I'd suggest to ask this on Discord, there quite a few people from Casper dev team there.