On Jul 23, 2017, at 8:54 PM, Philip McGrath <philip....@gmail.com> wrote:I'm confused about why the following program is blaming the server for the client's misuse of an applicable struct instance. More generally, I've tried doing this in several different ways, and I can't figure out how to make applicable structs that are still protected by contracts after deserialization and blame the client module for misusing them.Thanks,Philip#lang racket(module server racket(require racket/serialize)(provide (contract-out[adder (-> natural-number/c (-> natural-number/cnatural-number/c))]))(struct adder (base)#:property prop:procedure(λ (this x)(+ (adder-base this) x))#:property prop:serializable(make-serialize-info (λ (this) (vector (adder-base this)))#'deserialize-info:adder-v0#f(or (current-load-relative-directory)(current-directory))))(define/contract make-adder(-> natural-number/c (-> natural-number/cnatural-number/c))adder)
(define deserialize-info:adder-v0(make-deserialize-info make-adder(λ () (error 'adder"can't have cycles"))))(module+ deserialize-info(provide deserialize-info:adder-v0)))(require 'server racket/serialize)((deserialize (serialize (adder 5))) 'not-a-number)
--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#lang racket(module server racket
(provide (contract-out[adder (-> natural-number/c (-> natural-number/cnatural-number/c))]))(struct adder (base)#:property prop:procedure(λ (this x)
(+ (adder-base this) x))))(module intermediary racket(require (submod ".." server))(provide add5)(define add5(adder 5)))(require 'intermediary)(add5 'not-a-number)
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscribe@googlegroups.com.
On Jul 23, 2017, at 9:43 PM, Philip McGrath <phi...@philipmcgrath.com> wrote:Aha — so it isn't really an issue with serialization at all. If I (now) understand this correctly, when a function produces a contracted higher-order result, it is the responsibility of the caller of the original function to ensure that the result function is always applied to appropriate arguments. That would explain why this version blames intermediary:#lang racket(module server racket(provide (contract-out[adder (-> natural-number/c (-> natural-number/cnatural-number/c))]))(struct adder (base)#:property prop:procedure(λ (this x)(+ (adder-base this) x))))(module intermediary racket(require (submod ".." server))(provide add5)(define add5(adder 5)))(require 'intermediary)(add5 'not-a-number)I had previously intuited that the obligation would be on the caller of the result function, whoever that might be.
When serialization is in the mix, is there a correct way for server to protect itself from instances of adder being abused after they are deserialized?
On Jul 23, 2017, at 10:50 PM, Philip McGrath <phi...@philipmcgrath.com> wrote:If I'm following correctly, I think that's what I was trying to do, but I'm unclear how to give `make-deserialize-info` a variant of `make-adder` that has a contract. The initial example with `define/contract` was the closest I've come: it at least reported violations in terms of `make-adder` rather than `+`, but (as I now understand) it blamed the `server` module for all violations.-PhilipOn Sun, Jul 23, 2017 at 9:27 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:The original example had an explicit deserializer:
At Sun, 23 Jul 2017 19:54:43 -0500, Philip McGrath wrote:
> (define deserialize-info:adder-v0
> (make-deserialize-info make-adder
> (λ () (error 'adder
> "can't have cycles"))))
You're constructing the deserializer with `make-adder` --- the variant
from inside the `server` module, so it doesn't have a contract.
I think this is where you want to draw a new boundary by giving
`make-deserialize-info` a variant of `make-adder` that has a contract.
(module server racket(require racket/serialize)(provide (contract-out[adder (-> natural-number/c (-> natural-number/c natural-number/c))]))(struct adder (base)#:property prop:procedure(λ (this x) (+ (adder-base this) x))#:property prop:serializable(make-serialize-info (λ (this) (vector (adder-base this)))#'deserialize-info:adder-v0#f(or (current-load-relative-directory)(current-directory))))(define deserialize-info:adder-v0(make-deserialize-info
(λ (base)(define inst (adder base))(contract (-> natural-number/c natural-number/c)inst'(definition adder)`(deserialization ,inst)(object-name adder)#f))
(λ () (error 'adder "can't have cycles"))))(module+ deserialize-info(provide deserialize-info:adder-v0)))(require (submod "." server) racket/serialize)
((deserialize (serialize (adder 5))) 'not-a-number)